I would like to know if there's a faster way to select this:
document.getElementById('container')
.getElementsByTagName('p')[0]
.getElementsByTagName('strong')[1]
.innerText
The structure is:
<div id='container'>
<p>
<strong></strong>
<strong> what I would like to get</strong>
</p>
<div id='moredivs'>
</div>
<div id='moredivs'>
</div>
</div>
Faster, no - more elegantly, yes:
FIRST you need valid HTML:
console.log(
document.querySelector("#container > p > strong:last-child").textContent
);
<div id='container'>
<p>
<strong></strong>
<strong>Text I'd like to get</strong>
</p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With