I’m trying to create a simple button manager to select and eventually unselect allready checked img elements which contains CSS class .my_class, why this doesn’t work?
var last_selected;
$("img.my_class").click ( function () {
if (last_selected != null) alert ($(this) == last_selected); // returns false everytime
last_selected = $(this);
});
Each time you wrap
thisyou create a new jQuery object. Two jQuery objects are not equal to each other just because they wrap the same element ($(this) != $(this)).Instead, assign
thisitself tolast_selectedand everything should work as expected.