0

I am trying to get the table td texts by using Jquery and javascript

I have the following

//tables contain bunch of tables
  for(var i = 0; i < tables.length ; i ++){
        var table = tables[i];

        $(table 'td').each(function(){   //I know there is something wrong with my selector.
            $(this).text()
        })

The jquery selector doesn't work in my case. How do I select every td for different table?

Thanks for the help!

4

1 回答 1

5

我认为您想使用以下.find()方法:

$(table).find('td').each(function(){

演示:http: //jsfiddle.net/jfj47/

当然,另一种选择是使用“上下文选择器”:

$("td", table).each(function(){

演示:http: //jsfiddle.net/jfj47/1/

此外,如果tables只是 DOM 元素的数组(或类似数组的对象),您不必循环并可以使用:

$(tables).find("td").each(function(){

演示:http: //jsfiddle.net/jfj47/2/

参考:

于 2013-07-17T19:22:53.797 回答