Questions And Answers

More Tutorials

Jquery DOM Elements as selectors

jQuery accepts a wide variety of parameters, and one of them is an actual DOM element. Passing a DOM element to jQuery will cause the underlying array-like structure of the jQuery object to hold that element.

jQuery will detect that the argument is a DOM element by inspecting its nodeType.

The most common use of a DOM element is in callbacks, where the current element is passed to the jQuery constructor in order to gain access to the jQuery API.

Such as in the each callback (note: each is an iterator function).

 //the current element is bound to `this` internally by jQuery when using each
 var currentElement = this;
 //at this point, currentElement (or this) has access to the Native API

 //construct a jQuery object with the currentElement(this)
 var $currentElement = $(this);
 //now $currentElement has access to the jQuery API


In this page (written and validated by ) you learned about Jquery DOM Elements as selectors . What's Next? If you are interested in completing Jquery tutorial, your next topic will be learning about: Jquery HTML strings as selectors.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue:

Share On:

Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using, you agree to have read and accepted our terms of use, cookies and privacy policy.