/ 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.
Expand |
Embed | Plain Text
// 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() ); });
You need to login to post a comment.
