LoginSignup
4
4

More than 5 years have passed since last update.

appendした要素をクリックしたときに、$(this)を得るには

Last updated at Posted at 2013-07-03

やりたかったこと

appendした要素(#list liとする)をクリックしたときに、$(this)を得る

jQuery1.9まで

ぐぐったところ、このように書くらしい。
でもjQuery1.9からlive使えない・・・

$('#list li').live('click', function(){
    alert($(this));
    return false;
});

jQuery1.9から

色々試した感じ、これで行けそう。$(this)じゃないけど。

$('#list').on("click",$('li'),function(e){
    alert($(e.target));
    return false;
});

デモ:http://jsdo.it/Ituki/ag35

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