Answers for "Element executed at current focus jquery"

5

jQuery check element has focus

//test if element has focus in jQuery
if ($("#myElementID").is(":focus")) {
    //I have the focus
}

//test if element has focus in plain Javascript
var myElement = document.getElementById('myID');
if(myElement === document.activeElement){
    //myElement Has Focus
}
Posted by: Guest on August-01-2019
0

how to get focused element in jquery

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>focus demo</title>
  <style>
  .focused {
    background: #abcdef;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
 
<div id="content">
  <input tabIndex="1">
  <input tabIndex="2">
  <select tabIndex="3">
    <option>select menu</option>
  </select>
  <div tabIndex="4">
    a div
  </div>
</div>
 
<script>
$( "#content" ).delegate( "*", "focus blur", function() {
  var elem = $( this );
  setTimeout(function() {
    elem.toggleClass( "focused", elem.is( ":focus" ) );
  }, 0 );
});
</script>
 
</body>
</html>
Posted by: Guest on February-16-2021

Code answers related to "Element executed at current focus jquery"

Code answers related to "Javascript"

Browse Popular Code Answers by Language