最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using element object with jQuery method? - Stack Overflow

programmeradmin7浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论