I'm wondering why $(this)
is not working the way I'm expecting it to? In the code below, nothing happens when you click'Remove Image.' If you comment out the confirm statement then the background changes to green when you click 'Remove Image'. Do you know why this is? It seems like $(this)
is pointing to something else because of the confirm statement. Thanks in advance!
<a href="#" class='thumbnail the-one delete-file'><i class="icon-remove"></i>Remove Image</a>
$('.the-one').click(function(){
if(confirm("What do you say?")) { return true;} else {return false;}
$(this).css("background", "green");
});
You're returning before you set the css, so that line isn't getting executed. Try:
$('.the-one').click(function(){
if (confirm("What do you say?")) {
$(this).css("background", "green");
return true;
} else {
return false;
}
});
Because you have return
before it. Everything after return
won't run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With