Koerr
Koerr

Reputation: 15723

how to toggle addClass and removeClass?

my code:

<a href=# onclick="obj.addClass('fliph'); return false;">toggle</a>

i want click toggle to obj.addClass('fliph'),then click again run obj.removeClass('fliph').

how to fix my code?

thanks all! :)

Upvotes: 2

Views: 13091

Answers (2)

jAndy
jAndy

Reputation: 235962

Do it unobtrusive, whereever possible.

<a href=# class="fliph">toggle</a>

Javascript:

$(document).ready(function(){
   $('.fliph').click(function(){
       $(this).toggleClass('fliph');
   });
});

Upvotes: 10

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124758

Do you mean this?

<a href=# onclick="obj.toggleClass('fliph'); return false;">toggle</a>

Upvotes: 6

Related Questions