I want to match all drop-down items that have specific class, but only if that class don't have specific parent (by class as well).
Currently I found a way to only match those drop-down items that do not have the first class:
$("a.dropdown-item").not(".some_class");
But I need to match the not()
part for elements whose parent dropdown div doesn't have the unique_dropdown
as well
I tried the following but that didn't work:
$("a.dropdown-item").not("some_class", $(this).closest(".unique_dropdown"));
and
$("a.dropdown-item").not("some_class", $("a.dropdown-item").closest(".unique_dropdown"));
The html:
<div >
<div >
<ul>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
</ul>
</div>
</div>
<div >
<div >
<ul>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
</ul>
</div>
</div>
<div >
<div >
<ul>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
<li>
<a ></a>
</li>
</ul>
</div>
</div>
In the above example, I only want to match <a>
elements with some_class
that are children of the .dropdown
div without .unique_dropdown
class
CodePudding user response:
Not sure that I understood well, but I hope this does the trick
$(".dropdown:not(.unique_class) a.dropdown-item:not(.some_class)")