Created
October 28, 2012 11:24
-
-
Save raimon49/3968375 to your computer and use it in GitHub Desktop.
WEB+DB PRESS Vol.71『プログラマのためのjQuery再入門』新旧イベントAPIの対応周りの写経
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $(elem).on('type', 'selector', handler)が$(elem).delegate('selector', 'type', handler)と同等 | |
// 各td要素にaddEventListener相当の処理が実行される | |
$('table td').on('click', function(e) { | |
// td要素に対する処理 | |
$(this).css('color', 'red'); | |
}) | |
// 親のtable要素だけにaddEventListenerしておき処理を委譲してもらう | |
$('table').on('click', 'td', function(e) { | |
// td要素に対する処理 | |
$(this).css('color', 'red'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment