The focus() Event gets executed, when a field (Like an text or textarea field) gets focus.
<html>
<head>
<title> My First Programme </title>
</head>
<body>
<h1> JQuery </h1>
Type Something : <input type = "text">
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"> </script>
<script>
$('input').focus( function() {
$(this).css("background-color", "yellow")
});
</script>
</body>
</html>
So, if you look at the above code, we have an <input> element, that accepts a text.
<input type = "text">
Now, if we take a look at the JQuery statement,
$('input').focus( function() {
$(this).css("background-color", "yellow")
});At first we locate the <input> element,
$('input')Then we use the focus() event,
$('img').focus(...)And put the function inside focus() event to change the color of <input> element.
$('input').focusin( function() {
$(this).css("background-color", "yellow")
});And the function,
function() {
$(this).css("background-color", "yellow")
});Locates the current element (i.e. <input>) using this and changes the color of the <input> element.