My js Code
if ($("#fb_connect_sell,#fb_connect").hasClass("connected")){
}
how i can use multiple selector with single hasclass?
My js Code
if ($("#fb_connect_sell,#fb_connect").hasClass("connected")){
}
how i can use multiple selector with single hasclass?
Share Improve this question edited Oct 26, 2013 at 12:02 underscore 6,9077 gold badges43 silver badges81 bronze badges asked Oct 26, 2013 at 11:43 SadikhasanSadikhasan 18.6k23 gold badges83 silver badges126 bronze badges 2- 1 what do you want to check? whether one of the has the connected class or both has the class – Arun P Johny Commented Oct 26, 2013 at 11:49
- both class is connected or not if not then addclass for both and if yes then removeclass for both means toggle. – Sadikhasan Commented Oct 26, 2013 at 12:57
2 Answers
Reset to default 5If you want to check whether one of the elements has the class then use .is()
if ($("#fb_connect_sell,#fb_connect").is(".connected")){
}
if you want to check whether both has the class
if ($("#fb_connect_sell,#fb_connect").filter(".connected").length){
}
try
var $first = $("#fb_connect_sell");
var $second = $("#fb_connect");
if ($html.hasClass('connected') && $html.hasClass('connected')) {
// do stuff
}