Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access value in first cell of HTMLTableRowElement

Is it possible to access the value in the first cell of a HTMLTableRowElement as defined at : http://krook.org/jsdom/HTMLTableRowElement.html

like image 964
blue-sky Avatar asked Oct 26 '25 13:10

blue-sky


2 Answers

Yes. If your row is in a variable called tr, just access tr.cells[0] and get whatever you want from it.

like image 50
Niet the Dark Absol Avatar answered Oct 28 '25 03:10

Niet the Dark Absol


Old question, but I'd like to answer with something more appropriate that I believe the OP was looking for, based on the response

anSelected[0].cells[0].innerText which works, I'm looking for alternatives

According to MDN,

The cells property (HTMLTableRowElement.cells)

Returns a live HTMLCollection containing the cells in the row. The HTMLCollection is live and is automatically updated when cells are added or removed.

So we can now check MDN for HTMLCollection, take a look at the .item() method, which is described to do exactly what you want:

The method takes an index parameter, which is the position of the Node to be returned.

So, to avoid the following:

anSelected[0].cells[0].innerText

You can use the the .item() method:

anSelected.item(0).cells.item(0).innerText

like image 32
Justin Bess Avatar answered Oct 28 '25 03:10

Justin Bess



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!