17

I'm a beginner in JQuery,

How can I get the control as a javascript object from a JQuery object

var _object = $(this). ??
asked Mar 22, 2011 at 8:00

4 Answers 4

33

Most common var _object = $(this)[0];

If you have more than 1 elements matched: $(this)[0], $(this)[1], $(this)[2] and so on.

$(this).get() is also possible. It's only advantage over the array model is that it allows selection of the kind $(this).get(-1) where it gets you the last matched object

answered Mar 22, 2011 at 8:01
Sign up to request clarification or add additional context in comments.

Comments

0
var _object = $(this)[0];

I think this is right, can't check though because I'm on my phone.

ThiefMaster
320k85 gold badges607 silver badges648 bronze badges
answered Mar 22, 2011 at 8:02

Comments

0

In your case, simply use this.

$(this)[0] == this if this is a DOM element. If it's something else, e.g. a selector, $(this)[0] is the way to go.

answered Mar 22, 2011 at 8:08

Comments

0
(function (e) {
 var a = false;
 try {
 $(this)[0];
 a = true;
 } catch (h) {}
 alert(a.toString());
})(window);
answered Feb 22, 2013 at 10:13

1 Comment

You have accidentally created two accounts. For how to merge them, see the help.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.