Return to Snippet

Revision: 28792
at July 14, 2010 11:03 by scheurbert


Initial Code
// Placeholder text
jQuery('input[type=text]').bind('focus', function() {
	if ( $(this).attr('placeholder') && $(this).val() == $(this).attr('placeholder') ) $(this).val('');
}).bind('blur', function() {
	if ( $(this).attr('placeholder') && !$(this).val() ) $(this).val( $(this).attr('placeholder') );
}).each( function() {
	if ( !$(this).attr('placeholder') && $(this).val() != "" ) $(this).attr('placeholder', $(this).val() );
});

Initial URL


Initial Description
Just a quick script to enable default text within a form element to be cleared or restored upon focus/blur of a particular element.

Should give you roughly the same functionality as the new HTML5 webforms "placeholder" attribute.

Initial Title
Input Placeholder Script

Initial Tags
text, html5

Initial Language
jQuery