Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Bind method

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 259
    Comment on it

    Bind method is used for attaching an event handler to a document.As shown below click,double click,mouse enter, mouse leave are event handlers directly attached to the document.

    <!doctype html>
    <html lang="en">
    <head>
      <meta charset="utf-8">
      <title>bind demo</title>
      <style>
      p {
        background: yellow;
        font-weight: bold;
        cursor: pointer;
        padding: 5px;
      }
      p.over {
         background: #ccc;
      }
      span {
        color: red;
      }
      </style>
      <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    </head>
    <body>
     
    <p>Click or double click here.</p>
    <span></span>
    <div></div>
     
    <script>
        $(document).ready(function(){
            $("p").bind("click",function(event){
                $("span").text("click happened" );     
            });
            $("p").bind("dblclick",function(event){
                $("span").text("double click happened");
            });
            $("p").bind("mouseenter mouseleave",function(event){
                $(this).toggleClass("over");
            });
        });
    
    </script>
    </body>
    </html>
    

     

 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: