[英]How to select element has attribute and attribute not equal to specific value using jquery?
I got the following line: 我得到以下行:
$("element").find("[attr!='val'][attr!='val'][attr!='val'][attr!='val'][attr!='val']")
based on this answer. 基于此答案。 My page stops running.
我的页面停止运行。 My assumption is that it finds all the different elements in the page, also the ones that don't have the attribute.
我的假设是,它会找到页面中所有不同的元素,以及没有该属性的元素。 Is that correct?
那是对的吗? If so how can I fix this?
如果可以,我该如何解决? I tried the
我尝试了
$("element").not("[attr='val']")
// instead of
$("element").find("[attr!='val']")
and it still crashed the page. 并且它仍然使页面崩溃。 The following code works of course:
下面的代码当然可以工作:
$("element").find("[attr='val']")
JQuery Has Attribute Selector [name]
select element only has attribute without consider to it value. jQuery 具有属性选择器
[name]
select元素仅具有属性而不考虑其值。 You need to adding [attr]
at the first of your selector. 您需要在选择器的第一个添加
[attr]
。
$("ul").find("[class][class!='A']").css("color", "red");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul> <li class="A">A</li> <li class="A">A</li> <li class="B">B</li> <li>C</li> </ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.