4 ms·
Or just use vanilla JS
by bromuk 3y ago
Or just use vanilla JS
- Onewildgamer 3y agoOr just don't use JS
- _2z1p 3y agoModern 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.
- twiss 3y agoIndeed, 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_validation https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_va...
- lelandfe 3y agoIt’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.
- arp242 3y agoI 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.
- twiss 3y agoThose exist now: https://developer.mozilla.org/en-US/docs/Web/API/Element/remove https://developer.mozilla.org/en-US/docs/Web/API/Element/rem..., https://developer.mozilla.org/en-US/docs/Web/API/Element/prepend https://developer.mozilla.org/en-US/docs/Web/API/Element/pre...
- arp242 3y agoAh cheers, I didn't know that. I'll have to take a look.
- deleted 3y ago[deleted]
- kordlessagain 3y agoWhich, interestingly enough, an LLM can probably write quite well.