Skip to content

Instantly share code, notes, and snippets.

@kborchers
Created October 11, 2011 19:15
Show Gist options
  • Save kborchers/1279093 to your computer and use it in GitHub Desktop.
Save kborchers/1279093 to your computer and use it in GitHub Desktop.
:focus Selector Example
<!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