Using querySelector () to get the last td element

I have a variable that is node from dom. I managed to get to the place where I want to be:

myvar.querySelector('.tblItinPriceSummary tr') 

Gives me this:

 <tr> <td>Subtotal</td> <td align="right">$189.00</td> </tr> 

What I want is the textContent of the second td $ 189.

Is there anything I can add inside a querySelector to add it to .textContent to get this piece of data?

+6
source share
1 answer

You can use :last-child or :last-of-type to access the last td element inside the parent.

 document.querySelector('.tblItinPriceSummary tr td:last-child').textContent; 
+9
source

Source: https://habr.com/ru/post/984583/


All Articles