Similarities and differences of binding events bind of on of live of one of in jQuery

  • 2021-07-24 09:22:42
  • OfStack

Four ways to bind events in jQuery, which can bind one or more events at the same time

bind ()-----------version number less than 3.0 (removed in Jquery 3.0 and corresponding unbind ())

live ()---------version number less than 1.7 (removed in Jquery 1.7 and corresponding die ())

delegate ()--------version number less than 1.7 (removed in Jquery 1.7)

on ()--------version number greater than 1.7 (added in Jquery 1.7, corresponding to off ())

A: Usage of bind () Event


 <title> Binding event </title>
 <script src="js/jQuery1.11.1.js" type="text/javascript"></script>
 <script>
  $(function () {
   $("p").bind({
    "mouseover": function () {
     $("p").css("background-color", "red");
    },
    "mouseout": function () {
     $("p").css("background-color", "");
    }
   });
  });
 </script>
</head>
<body>
 <p>what are you doing?</p>
</body>
</html>

The first big difference is that the event binding of bind () is only valid for the selected elements on the current page. If you want an bind () event on a dynamically created element, there is no way to achieve the effect

on () is used in the following dynamic generation of DOM element binding events;


Related articles: