simonyoung
simonyoung

Reputation: 855

How do I rewrite this jQuery more efficiently?

How do I rewrite this code to change a class name with jQuery more efficiently?

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

Upvotes: 2

Views: 76

Answers (1)

Sjoerd
Sjoerd

Reputation: 75609

$(this).toggleClass('flipped');

Upvotes: 8

Related Questions