Hacker News new | ask | show | jobs
by bromuk 1103 days ago
Or just use vanilla JS
3 comments

I like being able to do elem.remove() instead of elem.parentNode.removeChild(elem), and elem.prepend(other) instead of elem.insertAdjacentElement('afterbegin', other). There's loads of stuff like this.

The DOM API does not spark joy.

Ah cheers, I didn't know that. I'll have to take a look.
Or just don't use JS
Modern CSS and HTML's built in elements are better at a lot of the things people use JS for.

I think as coders we feel most comfortable reaching for JavaScript first, when really we should be doing as much in HTML itself as possible, then prettying it all up with CSS, and then finally adding some JS for interactivity such as client side form validation.

Indeed, and even a lot of client side form validation can be done using HTML and CSS: https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_va...
It’s pretty limited, though, and has some random quirks. Like a required field will be marked as invalid immediately on load, or that it’s not really possible to display multiple errors on a single input.

You can work around them, but you’re approaching the complexity of just writing your own validator by that point.

Which, interestingly enough, an LLM can probably write quite well.