5

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?

2 Answers 2

8

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

var element = document.elementFromPoint(x, y);
$(element).offset();
Sign up to request clarification or add additional context in comments.

Comments

0

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/

1 Comment

OK, fail for me. I just read all the things about selectors without taking a look at the really easy methods... Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.