LoginSignup
2
2

More than 5 years have passed since last update.

jquery.one()で同時に複数の要素を指定した場合について。

Posted at

jquery_one

.one()

jquery.one()の実験です。
jquery.one()はjqueryに選択された、オブジェクトに一度だけイベントハンドラを登録するというメソッド。

jqueryによって選択されたオブジェクトが複数だった時に
oneでバインドしたイベントが発生した場合、すべてのオブジェクトに指定したハンドラが解除されるかの確認です。

こちらのリンクで確認できます。

http://prinum.github.io/jquery_one/

index.html

<body>
  <button>1</button>
  <button>2</button>
  <button>3</button>
  <button>4</button>
  <button>5</button>
</body>

app.js

$(document).ready(function(){
  $('button').one('click',function(){
    alert($(this).html()+'click!');
  });
});

結果として、解除されることはなく、それぞれにoneメソッドで指定したイベントハンドラが実行できる。

ソースコードです

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