I have a table. The table has some set of rows, each set containing 3 specific rows, and repeated downwards.
I want to have a variable i which should be incremented for each row (<tr>) having class="nm" or for each cell (<td>) having class="zxcv". The incremented result value i may be alerted finally.
How can I do this using JavaScript with / without jQuery?
You can see my JS Fidd开发者_如何学运维le here.
If you just want to get a count of <tr class="nm"> and <td class="zxcv">, using jQuery, do this:
alert($('tr.nm, td.zxcv').length);
EDIT:
To loop through each element, do this:
$('tr.nm, td.zxcv').each(function(index, elem) { /* do something */ });
I find your wording a bit unclear, but if you're trying to do something to each row with the class "nm" you could use the .each() function:
$('.nm').each(function(i,row) {
//$(row) is now your .nm row
alert(i);
});
加载中,请稍侯......
精彩评论