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
Post a Comment