Q:

using jquery Test if an input has focus?

0

using jquery Test if an input has focus?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code:

<!DOCTYPE html>
<html>
<head>
   <style>
  .focused {
    background: green;
  }
  </style>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
  <meta charset="utf-8">
  <title>Test if an input has focus</title>
</head>
<body>
<div id="content">
  <input tabIndex="1">
  <select tabIndex="3">
    <option>select menu</option>
  </select>
  <p tabIndex="3">
    A Paragraph
  </div>
</div>
</body>
</html>

JavaScript Code:
$( "#content" ).delegate( "*", "focus blur", function() {
  var elem = $( this );
  setTimeout(function() {
    elem.toggleClass( "focused", elem.is( ":focus" ) );
  }, 0 );

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now