开发者

Read td values using prototype

开发者 https://www.devze.com 2023-01-29 00:09 出处:网络
I would like to read the values of HTML td using prototype. For example, say you have a table as follows

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

精彩评论

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