开发者

Using element object with jQuery method?

开发者 https://www.devze.com 2023-01-19 18:07 出处:网络
I just started using jQuery. Now I want to use an jQuery method with an element object. var element = document.elementFromPoint(x, y);

I just started using jQuery. Now I want to use an jQuery method with an element object.

var element = document.elementFromPoint(x, y);
element.offse开发者_StackOverflow中文版t();

Of course this doesn't work because the variable element is not a jQuery selector, so the error message I get in Firebug is "element.offset is not a function". Is there any general method I could use this element object with an jQuery selector?


You can turn a normal DOM element into a jQuery selection by wrapping it in $():

var element = document.elementFromPoint(x, y);
$(element).offset();


You need to wrap it into the jQuery constructor function, which returns a jQuery object.

jQuery(element).offset();

or shortcut method

$(element).offset();

http://api.jquery.com/jQuery/

0

精彩评论

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