Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find from elements with one to multiple class names just the ones which feature exactly a specific and sole class name (and not any other)?

Example:

<div class="parent">
<div class ="parent father">
const soleParentClassElementList = document.querySelectorAll('.parent')

With the above code line I would query both element nodes, but I want to query just the one(s) with a single parent class.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

this way…

const onlyParent = document.querySelector('[class="parent"]')


onlyParent.textContent = 'this one'
<div class ="parent father">...</div>

<div class="parent"> ... </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading