Return to Snippet

Revision: 56705
at April 10, 2012 19:29 by Huskie


Initial Code
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);
	}
});

Initial URL
http://darrenhuskie.com

Initial Description
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.

Initial Title
Clear all text fields on focus based on original value with single function

Initial Tags
jquery, text, function

Initial Language
jQuery