0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

jQueryとeach()とreturn false

Last updated at Posted at 2020-04-14

なんてないことですけど備忘録。
$('hoge').each()
なんてので総当たりする。
ifを使って判定して条件にマッチしたときに処理を止めるとき

$('.hoge').each(function(){
 if(!$(this).hasClass('active')){
  $('.fuga').removeClass('active');
  return false;
 } else {
  $('.fuga').addClass('active');
 }
});

と、「return false;」を入れる。
もしページ内の.hogeに.activeが無ければそこで処理を止める。
ページ内の.hogeに全部.activeがあればelseを通ります。

忘れていたのでここに書いとく。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?