Using jQuery instead of document.getElement

advertisements

I would like to use

$("#fooid")

in place of

document.getElementById("fooid")

because I'm getting the id with the # in front of it. While you can remove it easily enough, there is a fair amount of intermixing between when I'm using a jQuery selector and when I'm using native DOM calls. In particular this is being called inside a chart draw, which seems to expect a native DOM object back. Giving it this extended jQuery object makes it choke and turn purple.

Is there a way I can get jQuery to "play nice" and pretend to give, or return instead, a native object?


You can use the get method to get the DOM object:

$("#fooid").get(0);

Or a bit shorter version:

$("#fooid")[0];