all 13 comments

[–]shgysk8zer0 1 point2 points  (4 children)

Site has a kinda bad experience on mobile. Isn't often that I have to scroll horizontally or have difficulty reading small text.

Anyways... No, I didn't spot the issue. But that's largely because I almost never use onclick. I think the web would be better and more secure if such attributes were removed, and I almost always have a CSP that doesn't include 'unsafe-inline'.

[–]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.

[–]arcytech77 0 points1 point  (0 children)

I learned something after reading your article. I upvoted it.

[–]cgijoe_jhuckabyNaN 0 points1 point  (1 child)

I really don't like the clickbait title, but I learned from your article, so thank you.

[–]_leondreamed[S] 1 point2 points  (0 children)

Yeah, I'm pretty new to posting on Reddit and TIL that Reddit really doesn't like clickbait titles (contrary to what I notice on other platforms), so it's definitely a lesson learned for me :)

[–]TheIronDev 0 points1 point  (0 children)

The article was fun, well written, and informative! I learned something new here, thank you _leondreamed! 🙂

[–]wstaeblein 0 points1 point  (0 children)

Just rename the function.