Last active
September 22, 2017 11:12
-
-
Save komagata/94533293aa037d205b081e03529d4a86 to your computer and use it in GitHub Desktop.
jQueryを使わず、動的にイベントリスナを追加する。
This file contains 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
let elements = document.getElementsByTagName("div"); | |
Array.from(elements, (element) => { | |
if (element.classList.contains(".foo")) { | |
element.addEventListener("click", () => { | |
console.log("FOO!"); | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQuery のコードは途中で心が折れたので読んでませんが、先の例で
ul.js-list
だけにイベントがついてるので、やっぱりバブルアップを使ってそうと思った。でも止めた方が・・・