Here is the HTML for the list item:
<li class="disabled-result" data-option-array-index="1" style="">4" (0)</li>
And here is the JS I'm trying to use, which isn't working:
var xpath = "li[contains(.,'4"')]";
var matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
matchingElement.setAttribute('style', 'display: none;" ) !important' );
Ideally I would just assign an ID to the list item I want to hide, but this is a Wordpress website and that makes it difficult to do.
Something I noticed is that in the page source, the <li>
html doesn't show up (only in inspector). I have the JS running in the footer.
Any help is greatly appreciated. I've been scratching my head over this.
(I also tried this without the var matchingElement
line. I'm not very familiar yet with using Xpath, and in the past have mostly used queryselector.)
Edit: Here is the entire code for the <UL>
<ul class="chosen-results">
<li class="active-result result-selected" data-option-array-index="0" style="">Size</li>
<li class="disabled-result" data-option-array-index="1" style="">4" (0)</li>
<li class="disabled-result" data-option-array-index="2" style="">5" (0)</li>
<li class="active-result" data-option-array-index="3" style="">Extra Large (5)</li>
<li class="active-result" data-option-array-index="4" style="">Large (7)</li>
<li class="active-result" data-option-array-index="5" style="">Medium (8)</li>
<li class="disabled-result" data-option-array-index="6" style="">Small (0)</li>
</ul>