I need help to select previously clicked element.. (I couldn’t find answer) My function is as follows:
showSticker:function(){
$(".Sticker").click(
function () {
if ($(this).hasClass("StickerShow"))
$(this).removeClass('StickerShow')
else {
$(".Sticker").removeClass('StickerShow'); // Here is a problem
$(this).addClass('StickerShow');
}
}
);
}
Actually it works good but I found it pretty dummy to remove class from all matched elements and I noticed that it’s pretty hard for CPU to render it.
seems you want like this:
if stickers are siblings you can use simple
$this.siblings('.StickerShow').removeClass('StickerShow')and$this.toggleClass('StickerShow')instead ofif/else