jQuery on() handle click event

Description

jQuery on() handle click event

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//from   w  w  w  .j av  a  2  s.  c o m
<script>
$(document).ready(function(){
  $("p").on("click", function(){
    $(this).css("background-color", "pink");
  });
  $("button").click(function(){
    $("p").off("click");
  });
});
</script>
</head>
<body>

<p>Click this paragraph to change its background color.</p>
<p>Click the button below and then click on this paragraph.</p>

<button>Remove the click event handler</button>

</body>
</html>



PreviousNext

Related