:focus Selector - Javascript jQuery Selector

Javascript examples for jQuery Selector:focus

Description

The :focus selector selects the element with focus.

The following code shows how to select the element that currently has focus:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("input").focus();
    $(":focus").css("background-color", "yellow");
});//w  w  w .java  2s . c  om
</script>
</head>
<body>

<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="button" text='test' />
</body>
</html>

Related Tutorials