Beta Version Sticker

Archive for June, 2009

jQuery Quick Tip #1 – Adding a class on focus

Monday, June 1st, 2009

I’ve been learning and messing around more with jQuery recently, so i thought it would be a good chance to share some of the stuff i’m learning.

The Problem

I needed to add a focus class to my form input when i clicked the mouse in the input box.  I then needed to remove that class and add it to the next input in the form.  Well here’s how i did it!

The Solution

$(function() {
$(”input[type=text]“).focus(function() {
$(this).addClass(’focus_class’);
return false;
});
});

$(function() {
$(”input[type=text]“).blur(function() {
$(this).removeClass(’focus_class’);
return false;
});
});