开发者

Why can't I loop through each of the table rows loaded dynamically in Jquery?

The table I am working with is loaded at runtime via ajax, I am trying to loop through all the rows in the table, using the code below:

alert("here"+jQuery('#contentItems table.tablesorter table tbody tr')); //I get here[Object 开发者_C百科object]
jQuery('#contentItems table.tablesorter table tbody tr').each(function(){
                alert("test");
           });

I get the first alert, but no alerts for test.

Oh and this code is running from the document's mouseup event.

Any suggetions?


It looks like you probably have an extra table tag in your selectors.

This:

'#contentItems table.tablesorter table tbody tr'

Might need to be:

'#contentItems table.tablesorter tbody tr'


have you tried:

jQuery.each(jQuery('#contentItems table.tablesorter table tbody tr'), function(){
    alert("test");
});


change it to

jQuery('#contentItems table.tablesorter tbody tr').each(function(){
                alert("test");
           });

I would also add one more thing if you dont have multiple tables with the same class i.e tablesorter you can just do

jQuery('table.tablesorter tbody tr').each(function(){
                alert("test");
           });

the performance gain by first filtering on id and then on the class will be negligible and the time for jquery to process these multi-level selector might just end up equaling the time of filtering on the id

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜