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

javascript - Using querySelector() to obtain last td element - Stack Overflow

programmeradmin1浏览0评论

I have a variable which is a node from the dom. I've managed to get all the way down to close to 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 of querySelector so that I can append it with .textContent to get this piece of data?

I have a variable which is a node from the dom. I've managed to get all the way down to close to 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 of querySelector so that I can append it with .textContent to get this piece of data?

Share Improve this question edited Apr 1, 2015 at 19:22 Josh Crozier 241k56 gold badges400 silver badges313 bronze badges asked Apr 1, 2015 at 19:12 Doug FirDoug Fir 21.2k52 gold badges190 silver badges336 bronze badges 1
  • linked - stackoverflow.com/q/5684811/104380 – vsync Commented Oct 12, 2018 at 15:04
Add a comment  | 

1 Answer 1

Reset to default 28

You could either use :last-child or :last-of-type to access the last td element within the parent.

document.querySelector('.tblItinPriceSummary tr td:last-child').textContent;
发布评论

评论列表(0)

  1. 暂无评论