HOW TO USE BIND() AND UNBIND() METHOD IN JQUERY.

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 694  View(s)
Ratings:
Rate this:
I want to use bind() and unbind() method in jquery. how to use this please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to use bind() and unbind() method in jquery.


    bind() and unbind() methods.it will simply attach and unattach code to one or several events on a set of elements.

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
          <script src="Scripts/jquery-2.1.4.js"></script>
    </head>
    <body>
        <a  id="bind"  style="text-decoration:none; color:#000; font-size:20px;" href="javascript:void(0);">Bind</a>
     
    <script type="text/javascript">
        $(function () {
            $("#bind").bind("click", function () {
                alert($(this).text());
            });
        });
    </script>

     <br />   <a id="unbind" href="javascript:void(0);" style="text-decoration:none; font-size:20px; color:#000;">Unbind</a>
    <script type="text/javascript">
      
        $(function () {
            $("#unbind").bind("click", function () {
                $("#unbind").unbind("click");
                alert("now disable click event");
            });
        });
    </script>
    </body>
    </html>

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!