Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Y B
14,136 PointsJQuery vs Native JS objects and methods
I've just finished the making an interactive webpage course and previously the JQuery course before that.
jQuery seems a lot simpler (not least because of the universal consistency across browsers).
However I have a question on the structure of methods used in JQuery vs the Native JS web API.
All the methods in JQuery seem to be on the JQuery object i.e. $('someSelector').method().
However in JS the methods seem attached to a variety of objects and are not valid for all of them. e.g. document, element, Node, ParentNode etc.... So in order to make notes on what the method will do I really need to reference the object too.
ie document.getElementbyID vs Element.getElementbyID (probably not the best example as it uses ID but hopefully you get what I mean).
Is my understanding correct do the methods in JS depend on the object where in JQuery they use a more universal format?
1 Answer
Andrew Shook
31,709 PointsYes and no. The methods in jQuery work exactly the same as the methods in vanilla JS. However, all the methods in jQuery are attached/used on the jQuery object, which is just a JS object. You are trying to compare jQuery to all of JS when a better analogy would be to compare jQ to JS's document object. Just like the document object, jQuery has certain methods that will work only on itself. The only difference between the two is that the document object is a specific object (i.e. it works only on document), while jQuery is a general purpose library/object that is designed to make work with the DOM via JS easier and smooth out some of the rough spots in JS.
Y B
14,136 PointsY B
14,136 PointsThanks I suppose I was trying to compare JQuery to the web API part of JS.