Below is the HTML code for the list item in question:
<li class="disabled-result" data-option-array-index="1" style="">4" (0)</li>
Here is my attempt at using JavaScript to hide this list item, but it's not working as expected:
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 prefer to assign an ID to the specific list item I want to hide, but due to constraints with this being a Wordpress website, that method is not feasible.
An observation worth noting is that the <li>
element does not appear in the page source, only in the inspector. The JavaScript code is placed in the footer of the page.
Any assistance on this matter would be highly appreciated as I have been struggling to find a solution.
(I also attempted the code without the var matchingElement
declaration. My knowledge of XPath is still limited, as I am more accustomed to using querySelector.)
Edit: Included below is the complete 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>