Click on the items above to verify that their onclick handlers are attached.
Then click on the button below to add a new item to the list and see if it has an onclick handler.
Check to see that the new item does NOT have the onclick event handler.
Now we repeat this with event delegation.
Our list starts with two items
Original clickable item 1 from list with delegation
Original clickable item 2 from list with delegation
Here is the button to add to the list with event delegation:
Check to see that the new item does NOT have the onclick event handler.
And we repeat again, using event delegation for only list items.
Notice that we were able to get a 'not a list item' message in the previous list, because
we tested for being at an li or not in our onclick handler.
Here, because that testing is managed by the on() method, we have no handler for clicking on the ul.
Our list starts with two items
Original clickable item 1 from second list with delegation
Original clickable item 2 from second list with delegation
Here is the button to add to the list with event delegation:
Check to see that the new item does NOT have the onclick event handler.