I want to select all the inputs in a form except those within a specific element.
Consider the following sample HTML:
<form id="myForm">
<input />
<input />
<div class="excluded">
<input />
<input />
</div>
</form>
The following doesn't work:
const myForm = document.getElementById("myForm");
const inputs = myForm.querySelectors(":not(.excluded) input");
I worked around it by setting special class names for those ones by doing this:
const exInputs = document.querySelectorAll(".excluded input");
exInputs.forEach(input => input.classList.add("excluded"));
Now, somewhere else, I could do this:
const inputs = myForm.querySelectorAll("input:not(.excluded)");
But, there must be a more straightforward method of excluding nested elements, right?!