Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing child element through parent class in JavaScript

Tags:

javascript

How can I access child element's innerHTML which has no class nor ID through parent element with class in JavaScript?

It should return only text between <b> tags.

<div class="parent element">
  <h5>
    some other text<b>text</b>
  </h5>
</div>
like image 770
Madis päev Avatar asked Feb 10 '26 08:02

Madis päev


1 Answers

var innerText=document.querySelector('.parent.element h5 b').innerText
console.log(innerText);
<div class="parent element">
  <h5>
    some other text<b>text</b>
  </h5>
</div>
like image 129
Karthik Avatar answered Feb 13 '26 04:02

Karthik



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!