toggle class in click event - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

toggle class in click event

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   w  ww.  j  av a  2 s  .co m*/
    $(".like").click(function(){
        console.log( $(this).hasClass('unlike') ? 'unlike' : 'like' );
       $(this).toggleClass("unlike like");
    });
    });

      </script> 
 </head> 
 <body> 
  <button class="like">Like</button>  
 </body>
</html>

Related Tutorials