开发者

Read td values using prototype

I would like to read the values of HTML td using prototype. For example, say you have a table as follows

<table id="myTable">
 <tr>
开发者_如何学Python    <td>apple</td>
    <td>orange</td>
    </tr>
  <tr>
    <td>car</td>
    <td>bus</td>
  </tr>
</table>

I would like to read the values - apple, orange, car and bus alone. I am unable to find a way to do it? Any help would be of great help.

Thanks, J


This should work:

var values = $$('#myTable td').collect(function(element) {
  // stripTags(), if you're only interested in the actual content
  return element.innerHTML.stripTags();
});


The following returns an array of strings.

$$('#myTable td').pluck('innerHTML');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜