An Interest In:
Web News this Week
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
- March 25, 2024
- March 24, 2024
- March 23, 2024
August 22, 2017 01:02 pm GMT
Original Link: https://css-tricks.com/slightly-careful-sub-elements-clickable-things/
Be Slightly Careful with Sub Elements of Clickable Things
Say you want to attach a click handler to a <button>
. You almost surely are, as outside of a <form>
, buttons don't do anything without JavaScript. So you do that with something like this:
var button = document.querySelector("button");
button.addEventListener("click", function(e) {
// button was clicked
});
But that doesn't use event delegation at all.
Event delegation is where you bind the click handler not directly to the element itself, but to an element higher up the DOM tree. …
Be Slightly Careful with Sub Elements of Clickable Things is a post from CSS-Tricks
Original Link: https://css-tricks.com/slightly-careful-sub-elements-clickable-things/
Share this article:
Tweet
View Full Article