/ Published in: jQuery
                    
                                        
Clear all text fields on focus based on original value with single function. The code checks for a 'title' attribute on each input with class 'text' and compares this to the current value of the field.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
var $originalValue = '';
$('.text').focus(function () {
$(this).addClass('active');
if ($(this).val() == $(this).attr('title')) {
$originalValue = $(this).val();
$(this).val('');
}
});
$('.text').blur(function () {
$(this).removeClass('active');
if ($(this).val() == '') {
$(this).val($originalValue);
}
});
Comments
 Subscribe to comments
                    Subscribe to comments
                
                