I have a image in which I wanted to call click and re-click function. So I used .toggle() function instead of .click() function but its hiding the image without click so I decided to make click and re-click function within .click() function like below:
$('.imgclass').click(function(){
$(this).addClass('btn');
if($(this).attr('class','btn')){
$(this).css('background-color','blue');
$(this).removeClass('btn');
} else {
alert('sorry');
}
});
But in my code else statement is not working. In the first click it add background-color to blue and remove its class and then it wouldn't find the class btn so it should alert 'sorry' but its not alerting. I think there is other best idea to make click and re-click function within .click() function. How to accomplish this?