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
2 Answers
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();