For example,
var relevantItems = ul.querySelectorAll('li.someClass[data-x=someData]')
Should only match these elements from the outer, referenced <ul>
:
<ul>
<!-- This <li> matches -->
<li class="someClass" data-x="someData">
<ul>
<!-- depending on the query, there may be some extra matches within the hierarchy, but these should not be searched or included in the results -->
</ul>
</li>
<!-- need to also includes additional matches like this one: -->
<li class="someClass" data-x="someData">
</li>
</ul>
Right now I have a couple of options:
Use JavaScript to loop over
childNodes
/children
array and compare theclassName
anddataset.x
variables traditionally.Give each
<ul>
its ownid
and use the#id>
prefix feature like so:ul.querySelectorAll('#' + ul.id + ' > li....')
Is there a simpler syntax, or alternative function, e.g. filtering the childNodes
List somehow, to achieve the same query? (without adding an external library i.e. jQuery)