I am facing an issue with selecting elements based on classes ending with either x-control-ui
or y-control-ui
:
<div class="x-control-ui">x-control: <output id="x-control-output"></output></div>
<input type="range" min="-4" max="4" step="0.1" value="0" class="param x-control-ui" id="x-control">
<div class="y-control-ui">y-control: <output id="y-control-output"></output></div>
<input type="range" min="-4" max="4" step="0.1" value="0" class="param y-control-ui" id="y-control">
When using the selector [attribute*="value"]
, it successfully selects all four elements:
document.querySelectorAll("[class*='-control-ui']")
NodeList(4) [div.x-control-ui.hidden, input#x-control.param.x-control-ui.hidden, div.y-control-ui.hidden, input#y-control.param.y-control-ui.hidden]
However, when changing *=
to $=
in the selector [attribute$="value"]
, no elements are being selected:
document.querySelectorAll("[class$='-control-ui']")
NodeList []
This behavior occurs despite both class names ending in control-ui
.
The problem persists across various browsers like Chrome and Firefox. I have reviewed documentation and consulted other resources which confirm that the $=
operator should select elements where the specified attribute (in this case, class
) ends with the provided text.
Despite trying different modifications to the selector, I have not been able to resolve the issue. What could I be overlooking?