Created
August 23, 2018 02:25
-
-
Save d-kang/98301f4373a4af3e0399aed1cda837a1 to your computer and use it in GitHub Desktop.
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
<html> | |
<head></head> | |
<body> | |
<ul id="todo-app"> | |
<li class="todo"><span>Walk the dog</span></li> | |
<li class="todo"><span>Pay bills</span></li> | |
<li class="todo"><span>Make dinner</span></li> | |
<li class="todo"><span>Code for one hour</span></li> | |
</ul> | |
<script> | |
const addListeners = () => { | |
const todos = document.querySelectorAll('.todo > span'); | |
for (let i = 0; i < todos.length; i++) { | |
const todo = todos[i]; | |
if (typeof todo === 'object') { | |
todo.addEventListener('click', (e) => { | |
e.target.style = 'text-decoration: line-through'; | |
alert(`Item ${i + 1}: "${e.target.innerText}" is done!`); | |
}); | |
} | |
} | |
}; | |
document.addEventListener("DOMContentLoaded", function (event) { | |
addListeners(); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment