user3117081
user3117081

Reputation: 91

Can you save $(this) as a variable?

Is it possible to save $(this) as a variable inside of a jquery event so that you can compare it against other varaibles holding elements? If so, how would you go about doing this?

Upvotes: 0

Views: 61

Answers (2)

user796443
user796443

Reputation:

I do this al the time! :)

var $el = $(this);

Note $ before el. This does nothing actually, it is for you to remember that this is jquery var.

Upvotes: 1

codingrose
codingrose

Reputation: 15699

Yes why not.

$(element).click(function(){ //any event
    var th = $(this);
});

Upvotes: 0

Related Questions