Home >>jQuery Tutorial >jQuery :focus Selector

jQuery :focus Selector

jQuery :focus Selector

jQuery :focus selector in jQuery is used to selects the element that currently has focus.

Syntax:
$(":focus")
Here is an Example of jQuery :focus Selector:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("input").focus();
$(":focus").css("background-color", "#db80ed");
});
</script>
</head>
<body>
<input type="text" />
</body>
</html>

Output:

No Sidebar ads