开发者

jQuery: ~= selector: How to get elements that *do not* contain given element in a specified tag

I have an input field of the following type

开发者_运维问答
<input data-of-type="football baseball basketball">

If I wanted to get all tags which have data-of-type "baseball", I'd use something like

$("[data-of-type~=baseball]")

However, what I want to do is get all elements that have a data-of-type set, but that data-of-type does not include baseball. In short, something like

$("[data-of-type!~=baseball]")

(which returns a syntax error)


Close but try this:

$('[data-of-type]').not("[data-of-type~=baseball]")

Or

$('[data-of-type]').filter("[data-of-type!=baseball]")

Or if you want:

$('[data-of-type][data-of-type!=baseball]')

http://api.jquery.com/attribute-not-equal-selector/


If there is another common type, you can say this: $("[data-of-type~='ball']").not("[data-of-type~=baseball]")

or

$("[data-of-type*='ball']").not("[data-of-type~=baseball]")


Perhaps using the not selector will help:

$("input:not[data-of-type~=baseball]")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜