Reputation: 303
I wanted to create something when cliked to the button the background should change one image to another image such as toggle
. However i used removeClass
and addClass
but not working. Here is my code.
html
<button>click</button>
jquery
var button = $('button').eq(0);
var html = $('html');
button.on('click', function(){
if(html.hasClass == 'have'){
alert('do');
html.css({
background : 'url(http://img.pixland.uz/u2080f129653m.jpg)'
}).removeClass('have');
}else{
html.css({
background : 'url(http://img.pixland.uz/u13301f281573m.jpg)'
}).addClass('have');
}
});
Upvotes: 0
Views: 66
Reputation: 82251
hasClass
should hasClass('have')
:
if(html.hasClass('have'));
Upvotes: 1