最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery multiple elements with single hasclass - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 5

If 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 

}
发布评论

评论列表(0)

  1. 暂无评论