Simple background color switcher problem
I have created a simple background color switcher and it switches color only on the first click, but doesn't remove it on the second.
Here's an excerpt of my HTML and jQuery in its entirety below it:
- <body>
- <button>
- Change
- </button>
- </body>
- $(document).ready(function(){
- if(!$('body').hasClass('bg')){
- $('button').click(function(event){
- $('body').addClass('bg');
- });
- }
- else{
- $('button').click(function(event){
- $('body').removeClass();
- });
- }
- });
Could you please help me resolve the issue and point out what am I doing wrong? Thank you.