javascript - Switching between two different classes jQuery -


having trouble getting following code work:

$('#changemode').button().click(function(){     $('#playfield').toggle(function() {         $(this).switchclass("gridview","plainview");     }, function() {         $(this).switchclass("plainview","gridview");    });       }); 

i cannot switch following div's class.

<div id="playfield" class="gridview"></div> 

any ideas?

edit: tried this:

$('#changemode').button().click(function(){     if ($('#playfield').attr('class') == "gridview"){         $('#playfield').removeclass("gridview");         $('#playfield').addclass("plainview");     } else {         $('#playfield').removeclass("plainview");         $('#playfield').addclass("gridview");     } }); 

and seems work fine, heck?

i wasn't aware of switchclass, perhaps thinking of toggleclass? anyways - had old code used (i having strange issues toggleclass):

$(this).removeclass("gridview").addclass("plainview");   or  $(this).toggleclass("gridview plainview"); 

and vice versa.

example:

$('#changemode').button().click(function(){     $('#playfield').toggle(function() {         $(this).toggleclass("gridview plainview");         //$(this).removeclass("gridview").addclass("plainview");      }, function() {          $(this).toggleclass("plainview gridview");         //$(this).removeclass("plainview").addclass("gridview");     });       }); 

but others have suggested toggleclass should work needs.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -