LoginSignup
1
2

More than 3 years have passed since last update.

jQuery での return false

Posted at

jQuery の構文に見られる return false を決まり文句のように書いてるとこがあったが何のために記述を入れておくのか調べたのでメモ。

■jQuery での return false

■ポイント
基本的にjs動作では、ある要素で発火したイベントはその全ての親要素に伝播していく。
と、いうところにあります。

下記通り、JavaScript とは意味がことなるので注意。

●jQueryでの return false
 親要素へのイベント伝播を止める


●JavaScript での return false
 親要素へのイベント伝播を止めない。


上記より、
return falseでイベントの伝播を止めたい場合は、jQueryを使う必要がある。

■javascriptで伝播を止めたい時

stopPropagation()
(jQuery での return false と同じ動きになる。)

■参照

1
2
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
1
2