Created
October 11, 2011 19:15
-
-
Save kborchers/1279093 to your computer and use it in GitHub Desktop.
:focus Selector Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
.focused { | |
background: #abcdef; | |
} | |
</style> | |
<script src="http://code.jquery.com/jquery-latest.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(e) { | |
var el = $(this); | |
setTimeout(function() { | |
el.toggleClass("focused", el.is(":focus")); | |
}, 0); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment