admin管理员组文章数量:1022784
$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){
// some code
});
What I want to achieve is to run some code if either one of the elements is clicked.
$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){
// some code
});
What I want to achieve is to run some code if either one of the elements is clicked.
Share Improve this question asked Apr 15, 2015 at 15:40 StevikStevik 1,1522 gold badges17 silver badges38 bronze badges 1-
write like this
'.SELECTOR1, #SELECTOR2'
use a – Nishit Maheta Commented Apr 15, 2015 at 15:41
2 Answers
Reset to default 6The Sizzle selector engine that jQuery uses follows the same rules as CSS. With that in mind you can separate selectors using ,
:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
Simply use a ma to do that:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
JSFIDDLE.
$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){
// some code
});
What I want to achieve is to run some code if either one of the elements is clicked.
$(document).on('click', '.SELECTOR1 OR #SELECTOR2', function(){
// some code
});
What I want to achieve is to run some code if either one of the elements is clicked.
Share Improve this question asked Apr 15, 2015 at 15:40 StevikStevik 1,1522 gold badges17 silver badges38 bronze badges 1-
write like this
'.SELECTOR1, #SELECTOR2'
use a – Nishit Maheta Commented Apr 15, 2015 at 15:41
2 Answers
Reset to default 6The Sizzle selector engine that jQuery uses follows the same rules as CSS. With that in mind you can separate selectors using ,
:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
Simply use a ma to do that:
$(document).on('click', '.SELECTOR1, #SELECTOR2', function(){
// some code
});
JSFIDDLE.
本文标签: jqueryJavascriptMultiple selectorStack Overflow
版权声明:本文标题:jquery - Javascript - Multiple selector - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745514732a2153987.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论