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)?

Viewed 51

Example:

<div class="parent father"> ... </div>
<div class="parent"> ... </div>
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.

1 Answers

this way...

document
  .querySelectorAll('[class="parent"]')
  .forEach(node => node.textContent = 'this one');
<div class="parent father"> ... </div>
<div class="parent"> ... </div>

Related