tags:

views:

6108

answers:

4

I'm struggling to find the right terminology here, but if you have jQuery object...

$('#MyObject')

...is it possible to extract the base element? Meaning, the equivalent of this:

document.getElementById('MyObject')
+11  A: 

Take a look at http://docs.jquery.com/Core/get#index

VolkerK
+10  A: 
$('#MyObject').get(0);

I think that's what you want. I think you can also reference it like a regular array with:

$('#MyObject')[0];

But I'm not sure if that will always work. Stick with the first syntax.

Aaron Wagner
+1  A: 

Isn't the JQuery object just a wrapper around the DOM element? Meaning that $('#MyObject') is the same as document.getElementById('MyObject') but it has some additional functions.

Can you tell us a little more about what you're trying to do?

Mark Biek
no, jQuery is different from Prototype, it avoids mucking with DOM prototypes.
just somebody
+4  A: 

A jQuery object is a set of elements. In your case, a set of one element. This differs from certain other libraries, which wrap single elements and provide alternate syntax for selectors that return multiple matches.

Aaron W and VolkerK already explained how to access the first (index 0) element in the set.

Shog9