I think a lot of people owe a lot of thanks to jquery.
But in 2022 vanilla javascript is all you really need.
I think a lot of people owe a lot of thanks to jquery.
But in 2022 vanilla javascript is all you really need.
// jquery
$(selector).on('click', fn)
// vanilla js
document.querySelectorAll(selector).forEach(el =>
el.addEventListener('click', fn)
)Having said that, for the sake of 25kb - if you use more than a handful of features you might as well just include it.
It takes only 1 minute to write a wrapper, so you will write one, and I'll write one, and your dog will write one.
But most of the time, you find you need another wrapper, and then another, and the next thing you know you have most of jQuery, just not as uniform or as well tested.
I've seen this with database ORMs also.
your npm's dependencies authors cat will write a small wrapper and wont know about yours.
It's even easier if you copy paste from here: https://anguscroll.com/just/
At the very least there are some jQuery alternatives that are modular, smaller, and have less backwards compatibility like iirc zepto.
document.addEventListener('click', function(e){ var t = e.target;
if(t.closest('.foo') && t.nodeName.toLowerCase() === 'button'){
e.preventDefault();
// do stuff here
}
else if(t.closest('.bar') && t.nodeName.toLowerCase() === 'a' && t.classList.contains('here')){
e.preventDefault();
// do smth else here
}
}, false);one listener to rule them all...?
elegant enough and once you get used to it...
.closest can be pollyfilled too..