74

Possible Duplicate:
How to get a DOM Element from a JQuery Selector

I can select a node using jQuery with something like $('#element_id') but how would I get the DOM element for use with non-jQuery functions that expect something like would be returned by document.getElementById()?

Community
  • 1
  • 1
mpen
  • 256,080
  • 255
  • 805
  • 1,172

1 Answers1

128

You can retrieve DOM elements using array notation:

$("#element_id")[0]

or with get():

$("#element_id").get(0)
cletus
  • 599,013
  • 161
  • 897
  • 938
  • 1
    Works perfectly, thank you :) I was looking through the jQuery API but I wasn't quite sure what to look for. All I found was `.context`. – mpen Feb 23 '10 at 05:07
  • **Not working** with DOM's attribute nodeValue. Ex. `$("#element_id").[0].nodeValue`... see http://stackoverflow.com/a/18418270/287948 and http://jsfiddle.net/b80nskbw/ – Peter Krauss Mar 12 '15 at 15:00
  • 1
    @PeterKrauss `[0]` is not a method call -- remove the dot. `$("#element_id")[0].nodeValue` works. – NReilingh Dec 04 '15 at 05:58