How to use javascript/jquery to loop through table? -
i have block of code below
<tbody class="society_list"> <tr> <td>1</td> <td>dummy</td> <td>dummy</td> <td id="lol0">update this</td> </tr> <tr> ..... </tr> </tbody>
what want loop through whole table, find td id, value of id, , update html inside. have now(sorry i'm quite new , still don't have idea do...)
function update(){ var trs = document.queryselectorall('.society_list tr'); for(i=0;i<trs.length-1;i++){ trs[i].find('td').each(function(){ //i know need here what's that.. }); } }
iterate through tds have id attribute using has attribute selector.
$('.society_list tr td[id]').each(function(){ var tdid = $(this).attr('id'); // <--- getting id here var result = dosomemagicwithid(tdid); // <--- doing $(this).html(result); // <---- updating html inside td });
Comments
Post a Comment