/ Published in: jQuery
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.
Should give you roughly the same functionality as the new HTML5 webforms "placeholder" attribute.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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() ); });