jQueryで動的に追加した要素でイベントを起こしたい時


ajaxで追加した要素に対してjQueryのclickイベントが動作しなかったのでメモ。

処理の流れを考えると当然なのかもしれないが、ややこしいことはしたくなかったのでいろいろ調べてみたら解消してくれるものがあった。

$("#hoge").live('click', function() {
});

live()を使えば動的に追加したものを取得することができた。
これは便利!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>