最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Jquery multiple elements with single hasclass - Stack Overflow

matteradmin7PV0评论

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 

}
Post a comment

comment list (0)

  1. No comments so far