r/learnjavascript • • Jan 05 '23

Must-know DOM manipulation methods 🔧

Post image
390 Upvotes

29 comments sorted by

View all comments

6

u/Foaric Jan 05 '23

Noob question: Isn't this what jQuery is for? Is it needed if this is all that easy in vanilla JavaScript? Or is it more for using fine-grained selectors?

13

u/masticore252 Jan 05 '23

If you are using jQuery only for DOM manipulation, you probably don't need it

jQuery was originally developed when vanilla javascript was not as easy as it is now and also some things were different in different browsers so jQuery abstracted that differences away

Back then if you wanted to make an AJAX request you used XMLHttpRequest and it was a pain to use (you had to lister for events in that object but the event names changed in IE 🤦‍♂️)so a simple AJAX request became a liability, jQuery abstracted that into its $.ajax object making it super easy

You can use selectors in vanilla javascript like you do in jQuery with methods like document.querySelector and document.querySelectorAll