Create Div and set style and add click event handler - Javascript jQuery

Javascript examples for jQuery:Mouse Event

Description

Create Div and set style and add click event handler

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
   </head> 
   <body> 
      <script>
    $('body').html('<div id = "box">123</div>');
    $('#box').css('color','green');
    $('#box').css('font-weight','500');
    $('#box').click(function(){
        console.log('You clicked here');
    });/*w  ww .  j  a  v a2s  .  c  om*/

      </script>  
   </body>
</html>

Related Tutorials