Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Jquery on() method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 233
    Comment on it

    Hello Readers,

    on() is the jQuery method and it comes in jQuery 1.7 and it is the replacement of bind() and delegate() handlers methods and it is used to attach event to the currently selected elements and it is a faster way to attach to the event handler.

    Syntax :

    $(elements).on(events [, selector] [, data], handler);

    selector : It is optional parameter and it is a Selector String

    data : it is also a optional parameter and it is any data to pass to the handler when the event is triggered

    handler : when the event is triggered handler function execute.

    Code Example :

    <html>
    
       <head>
          <title>The jQuery Example</title>
          <script type = "text/javascript" 
             src = "http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    
          <script type = "text/javascript" language = "javascript">
             $(document).ready(function() {
                $('div').on('click', function( event ){
                   alert('Hi there');
                });
             });
          </script>
    
          <style>
             .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
          </style>
       </head>
    
       <body>
    
          <p>Click</p>
    
          <div class = "div" style = "background-color:blue;"></div>
    </body>
    
    </html>
    

    In the above code, we use the on() method and take the div as a selector and on click execute the event handler function and give the alert message.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: