click div with jQuery - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

click div with jQuery

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(){/*  w ww.j  a va 2s.  c  om*/
$('div').click(function(){
  $(this).css('color','red');
});
$('div').click();
    });

      </script> 
 </head> 
 <body> 
  <div>
    click 
  </div> 
  <div style="color:blue">
    I should be blue 
  </div> 
  <div style="color:green">
    I should be green 
  </div>  
 </body>
</html>

Related Tutorials