2010-08-24 33 views
2

如何重寫此代碼以更有效地使用jQuery更改類名?如何更有效地重寫這個jQuery?

$(function() { 
    $('#container').click(function(event) { 
     var element = event.currentTarget; 
     /* Toggle the setting of the classname attribute */ 
     element.className = (element.className == 'card') ? 'card flipped' : 'card'; 
    }); 
}); 

回答

8
$(this).toggleClass('flipped'); 
+0

唉唉的風采! – jathanism 2010-08-24 19:36:15