最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get value of child element of Object collection using jQuery? - Stack Overflow

programmeradmin3浏览0评论

I have HTMLTable with some rows and columns. I'm binding a function to the cell of this table on click. Inside this function I need to get value of first cell in this selected row. I have the following:

$(this).parent().children() 
gives me object with 4 HTMLTableCellElement like on the picture

I need to get text that contains innerHTML of [0] element:

How to get this text?

If I use $(this).parent().children('0').innerHTML it gives me "undefined"

I have HTMLTable with some rows and columns. I'm binding a function to the cell of this table on click. Inside this function I need to get value of first cell in this selected row. I have the following:

$(this).parent().children() 
gives me object with 4 HTMLTableCellElement like on the picture

I need to get text that contains innerHTML of [0] element:

How to get this text?

If I use $(this).parent().children('0').innerHTML it gives me "undefined"
Share Improve this question edited Aug 17, 2018 at 9:02 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Nov 11, 2013 at 18:33 BryukBryuk 3,34511 gold badges49 silver badges76 bronze badges 1
  • this.parentNode.cells[0].innerHTML – Blue Skies Commented Nov 11, 2013 at 18:39
Add a ment  | 

2 Answers 2

Reset to default 4

.children() returns an array of DOM elements. You can simply grab the first element in the array:

$(this).parent().children()[0].innerHTML

Pretty close, try:

$(this).parent("tr").find("td:first").text();
发布评论

评论列表(0)

  1. 暂无评论