开发者

Using jQuery in place of document.getElement

开发者 https://www.devze.com 2023-01-19 15:51 出处:网络
I would like to use $(\"#fooid\") in place of document.getElementById(\"fooid开发者_JAVA技巧\") because I\'m getting the id with the # in front of it. While you can remove it easily enough, ther

I would like to use

$("#fooid")

in place of

document.getElementById("fooid开发者_JAVA技巧")

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];


With .get()

0

精彩评论

暂无评论...
验证码 换一张
取 消