using jquery Test if an input has focus?
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 );
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code:
JavaScript Code: