jQuery Selector :focus

Introduction

The :focus selector selects the element that currently has focus.

$(":focus")

Select the element that currently has focus:

View in separate window

<!DOCTYPE html>
<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", "yellow");
});/*from w w  w .j  a  va 2  s.  co  m*/
</script>
</head>
<body>

<input type="text" />

</body>
</html>



PreviousNext

Related