开发者

jquery with two or more sub selectors

开发者 https://www.devze.com 2023-01-26 22:56 出处:网络
How do I write a selector that has two condtional selectors, eg $(\"#version optio开发者_开发知识库n:selected **AND** option:contains(\'some text\')\")

How do I write a selector that has two condtional selectors, eg

$("#version optio开发者_开发知识库n:selected **AND** option:contains('some text')")


Just like you can use :visited:hover in CSS, you could do the same in jQuery:

$("#version option:selected:contains('some text')")


http://api.jquery.com/multiple-selector/

BTW, the correct usage would be in your case:

$("#version option:selected, #version option:contains('some text')")

or

$("#version").find("option:selected, option:contains('some text')")

not

$("#version option:selected, option:contains('some text')")


You can match on multiple attribute selectors by simply chaining further sub 'find' calls.

For example:

$("#version option:selected").find(":contains('some text')") //and so forth


You separate the selectors by commas:

$("#version option:selected,#version option:contains('some text')")

http://api.jquery.com/multiple-selector/

Update

Even though this is not what the OP was looking for I updated my post in case someone stumbles upon this in the future. Thanks to RoToRa for catching the error.

0

精彩评论

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