[英]Exclude <li> with specific text in <a> tag of its children
I want to exclude <li>
with specific text in the <a>
tag我想用
<a>
标签中的特定文本排除<li>
HTML:- HTML:-
<ul>
<li class ="Group Select">
<span><a>Good</a></span>
</li>
<li class ="Group NotSelect">
<span><a>Bad</a></span>
</li>
<li class ="Group NotSelect">
<span><a>What</a></span>
</li>
<li class ="Group NotSelect Hidden">
<span><a>Better</a></span>
</li>
<li class ="Group NotSelect">
<span><a>Best</a></span>
</li>
<li>
<span><a>BadDuplicate</a></span>
</li>
In The end, I want li with class Group Select or Group NotSelect but not Group NotSelect Hidden and I do not want li which has "What" in its <a>
tag最后,我想要类 Group Select 或 Group NotSelect 但不是 Group NotSelect Hidden 的 li,我不想要
<a>
标签中有“What”的 li
So far迄今为止
$possibleli = $('li.Group').not("[class='Group NotSelect Hidden']");
This gives me all li's
that I need but I want to remove li that has what in its <a>
tag这给了我我需要的所有
li's
,但我想删除<a>
标签中包含内容的 li
Use the :contains() selector combined with the .not function (or the not selector combined with the :contains selector) like this:将:contains()选择器与 .not 函数结合使用(或 not 选择器与 :contains 选择器结合使用),如下所示:
$possibleli = $('li.Group').not("[class='Group NotSelect Hidden']").not(':contains(What)');
or或者
$possibleli = $('li.Group:not(.Hidden):not(:contains(What))');
$(".Group.Select, .Group.NotSelect").not(".Hidden, :contains('What')").addClass("red");
.red{background:red;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> I want li with class Group Select or Group NotSelect <br> but not Group NotSelect Hidden <br>and I do not want li which has "What" in its A tag <ul> <li class ="Group Select"> <span><a>Group Select</a></span> </li> <li class ="Group NotSelect"> <span><a>Group NotSelect</a></span> </li> <li class ="Group NotSelect"> <span><a>What</a></span> </li> <li class ="Group NotSelect Hidden"> <span><a>Group NotSelect Hidden</a></span> </li> <li class ="Group NotSelect"> <span><a>Group NotSelect</a></span> </li> <li> <span><a>BadDuplicate</a></span> </li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.