Reputation: 2861
Ok, so as i am working on a development project, i started doing my normal object reference acquisition var obj = $(".selector");
but then noticed that when i tried to operate on this reference it was not the root object.
Currently have JQuery 2.1 & JQuery UI 1.10.4 in the link folder.
Any explanation as to why i have use the Index 0 to get a reference to the html control?
Upvotes: 0
Views: 59
Reputation: 3769
The jQuery selector returns a jQuery QuerySet
object, which includes the set of results matching the query. It also allows you to call jQuery functions on the result, such as .text()
, .addClass()
, etc., instead of using the JavaScript DOM API.
As for why elements are accessible through indexing (vs, say, a property called domElement
or something): remember that jQuery selector queries can return multiple elements. Imagine, for example, if you had multiple elements with the class "selector". Then wnd[0]
will return the first matching DOM element, and wnd[1]
will return the second matching DOM element.
Upvotes: 2