Home > DeveloperSection > Forums > How to use bind() and unbind() method in jquery.
Ankit Singh

Total Post:341

Points:2389
Posted on    January-19-2016 10:15 PM

 JQuery JQuery  JavaScript 
Ratings:


 1 Reply(s)
 333  View(s)
Rate this:
I want to use bind() and unbind() method in jquery. how to use this please help me.


aditya kumar Patel

Total Post:250

Points:1782
Posted on    January-19-2016 10:40 PM


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>


Don't want to miss updates? Please click the below button!

Follow MindStick