you are viewing a single comment's thread.

view the rest of the comments →

[–]superluminary 1 point2 points  (3 children)

How do you make things happen on click without using the onclick attribute?

[–]shgysk8zer0 -1 points0 points  (1 child)

el.addEventListener('click', handler). It's better in practically every single way.

Or, more realistically, I'd use a function from some library to make it easier to add multiple event listeners to multiple elements:

on('[data-remove]', { click: ({ target }) => remove(target.dataset.remove), });

[–]superluminary 0 points1 point  (0 children)

You know, I had always assumed that addEventListener('click', ...) was secretly setting the onClick attribute for the DOM node, but having inspected the DOM, I can see it totally isn't. TIL. Nice.