The off() Event is used to remove the events associated to an element those were created using <<<Click Here Begins>>>on() event<<<Click Here Ends>>>>. Let us see them one by one in the below examples.
The off() Event can be used to detach an event created by on() event.
<html>
<head>
<title> My First Programme </title>
</head>
<body>
<h1> JQuery </h1>
Type something : <input type = "text"> <br/><br/>
<button> Click on the Button first to Detach </button>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$("input").on("focus", function() {
$(this).css("background-color", "yellow")
});
$("button").click(function() {
$("input").off("focus")
});
</script>
</body>
</html>
So, in the above example, we have used the JQuery statement,
$("input").on("focus", function() {
$(this).css("background-color", "yellow")
});To change the background color of the <input> element to yellow, when you click on the <input> element(i.e. When it gets focused).
In the next JQuery statement,
$("button").click(function() {
$("input").off("focus")
});We have used the off() event to remove the focus event from the <input> element.