开发者

JQuery find not working for tr element?

Just wondering if anyone knows why the following code doesn't work (each() is not executed at all)...it works if i try td elements but not tr elements for some reason?

The html is returne开发者_如何学JAVAd by a php script and looks like

<tr class="my_files_row"><td>bla</td><td>bla</td></tr>


function update(html)
{
    $(html).find('tr').each(function()
    {
        alert('success');
    })
}

Thanks in advance!


I think your php should return the tr inside other element (a table perhaps). As the JQuery documentation states, find searches on "descendants" of the element, and tr is not a descendant of tr in your html. You can change the response to:

<table> <tr class="my_files_row"><td>bla</td><td>bla</td></tr> </table>

and that should work.


Find only finds descendants. In your case, tr is the root.


If you're interested in all TR elements and not those of a particular table/tbody/thead/tfoot element, then ask the right question (and don't be more complicated than you need to be). This:

$('tr').each(function(){
  var tr = $(this) ;
  ...
}) ;

should do you. If you need to be more specific table, you just to refine your selector:

$('table#mySpecialTable tbody tr')

The above gives you all elements in the of the table with id mySpecialTable.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜