admin管理员组

文章数量:1321823

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

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

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?

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

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

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?

Share Improve this question asked Oct 13, 2010 at 20:42 CharlyCharly 531 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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./jQuery/

本文标签: javascriptUsing element object with jQuery methodStack Overflow