Hi, I'm trying to understand what differences are between $(this)
and this
in jQuery
, and eventually find a way to get $(this)
object from this
(this
what??):
var last_btn;
$("#element").click (function () {
if (last_btn != null && last_btn == this) {
// to unselect the current button
last_btn.removeClass ("selected"); // doesn't work because this is not $(this)
} else {
if (last_btn != null) last_btn.removeClass ("selected"); // to unselect another old button
last_btn = this;
$(this).addClass ("selected");
}
});
As written in this post, I need to use this
instead of $(this)
object because it's the only way to assign a jQuery
object to a var without loose his instance.
How can I do that?