Javascript examples for jQuery:Mouse Event
toggle class in click event
<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>