admin管理员组文章数量:1323035
Is there way to get true when match both selectors class and data attribute ?
Find matched dropdown e.g:
`<select class="type-featured" data-featured="normal">`
....
`<select class="type-featured" data-featured="classical">`
....
`<select class="type-featured" data-featured="modern">`
Find select, class equal to type-featured AND data-featured value equal to normal - here is code:
$('.style-wrapper').each( function() {
var $styles = $(this);
if ( $styles.parents().find('select').is('.type-featured, [data-featured=normal]') ) {
// do something here
}
});
I got TRUE whether select has type-featured
class OR data-featured="normal", data-featured="classical", data-featured="modern"
Its seems to be TRUE if match any one selector.
Is possible to get my desired result using .is function? May be using anonymous function like :
.is( function() {
//here some logic to result
});
Is there way to get true when match both selectors class and data attribute ?
Find matched dropdown e.g:
`<select class="type-featured" data-featured="normal">`
....
`<select class="type-featured" data-featured="classical">`
....
`<select class="type-featured" data-featured="modern">`
Find select, class equal to type-featured AND data-featured value equal to normal - here is code:
$('.style-wrapper').each( function() {
var $styles = $(this);
if ( $styles.parents().find('select').is('.type-featured, [data-featured=normal]') ) {
// do something here
}
});
I got TRUE whether select has type-featured
class OR data-featured="normal", data-featured="classical", data-featured="modern"
Its seems to be TRUE if match any one selector.
Is possible to get my desired result using .is function? May be using anonymous function like :
.is( function() {
//here some logic to result
});
Share
Improve this question
edited Apr 27, 2017 at 4:37
miken32
42.8k16 gold badges123 silver badges173 bronze badges
asked Jan 24, 2017 at 13:01
Nand LalNand Lal
7021 gold badge12 silver badges25 bronze badges
0
2 Answers
Reset to default 7If you deploy the jQuery:
$('select.type-featured[data-featured="normal"]').each(function(){
// [... DO SOMETHING...]
});
you will run the function on only those <select>
elements which have:
class="type-featured"
data-featured="normal"
Instead of is(...)
try with hasClass()
- this determine whether any of the matched elements are assigned the given class.
本文标签: javascriptHow to find match selectors class and data attribute using jqueryStack Overflow
版权声明:本文标题:javascript - How to find match selectors class and data attribute using jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742108816a2421149.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论