The on() Event is one of the most important event in JQuery. It has various functionalities that is quite useful.
Let us see them one by one in the below examples.
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> Type something : <input type = "text"> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> <script> $("input").on("focus", function() { $(this).css("background-color", "yellow") }); </script> </body> </html>
$("input").on("focus", function() { $(this).css("background-color", "yellow") });
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> Type something : <input type = "text"> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> <script> $("input").on("keypress blur", function() { $(this).css("background-color", "yellow") }); </script> </body> </html>
$("input").on("keypress blur", function() { $(this).css("background-color", "yellow") });
<html> <head> <title> My First Programme </title> </head> <body> <h1> JQuery </h1> Type something : <input type = "text"> <script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script> <script> $("input").on( { focus : function() { $(this).css("background-color", "yellow") }, keypress : function() { $(this).css("background-color", "orange") }, blur : function() { $(this).css("background-color", "violet") } }); </script> </body> </html>
$("input").on( { focus : function() { $(this).css("background-color", "yellow") }, keypress : function() { $(this).css("background-color", "orange") }, blur : function() { $(this).css("background-color", "violet") } });
focus : function() { $(this).css("background-color", "yellow") }
keypress : function() { $(this).css("background-color", "orange") }
blur : function() { $(this).css("background-color", "violet") }