Skip to content

Instantly share code, notes, and snippets.

@jsven69gist
Created January 25, 2014 11:05
Show Gist options
  • Save jsven69gist/8614824 to your computer and use it in GitHub Desktop.
Save jsven69gist/8614824 to your computer and use it in GitHub Desktop.
jQuery: Set background-color on focus with addClass
// Add colorclass 'yellow' (background-color: #FFFF66) on focus to elements with class 'text'
$('.text').on('focus', function(event) {
$(this).addClass('yellow');
});
// Remove added colorclass 'yellow' on blur from elements with class 'text'
$('.text').on('blur', function(event) {
$(this).removeClass('yellow');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment