Converting a jQuery Object to Native DOM Element

jQuery is a great JavaScript library that abstracts away the pain in HTML document transversal and manipulation, event handling, animation, and Ajax with an easy-to-use API that works across multiple browsers.

A need to convert a jQuery object to native DOM element may arise in your future project and the conversion is easy as calling get() method on the object likes so:

$("#hello").get(0)

The code above is equivalent to plain JavaScript document.getElementById( "hello" )

Without a parameter, .get() returns an array of all matched elements.

For example, say your web page has a div tag containing a headline class, the following will return an array of the three div DOM elements.

$("div.headline").get()

Instead of calling .get() method on the jQuery object, you can also array dereference the object to return its DOM element like so

$("#hello")[0]
$("div.headline")[]

Resources

* How do I pull a native DOM element from a jQuery object?
* jQuery .get()

Don’t miss out!
Subscribe to My Newsletter
Invalid email address