Source Code:
(back to article)
Submit
Result:
Report an issue
<ul id="myList"> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> <!-- More items can be added dynamically --> </ul> <script> document.getElementById('myList').addEventListener('click', function(event) { if (event.target.tagName === 'LI') { alert('You clicked on ' + event.target.textContent); } }); </script>