Jquery on click for any element with class - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Jquery on click for any element with class

Demo Code

ResultView the demo in separate window

<html lang="en">
 <body translate="no"> 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 
  <script>
    $(document).ready(function(){
        $("#element").click(function(){
            if($(this).hasClass("hide")){
              $(this).slideUp(200);/*  ww w. j  a  va2s  .  com*/
            }
        });
    });    
      </script> 
  <button id="element" class="hide">Element 1</button> 
  <button id="element" class="show">Element 2</button>  
 </body>
</html>

Related Tutorials