A small plugin to inject a text into inputs ortextareas as a label.
The text is removed when the element is focused and re-injected onblur if the element is leaved blank.
Here is the code to include in an external js or to paste on the page:
jQuery.fn.smartFocus = function(text) {
$(this).val(text).focus(function(){
if($(this).val() == text){
$(this).val('');
}
}).blur(function(){
if( $(this).val() == '' ){
$(this).val(text);
}
});
};
USAGE EXAMPLE:
var mail = '* E-mail';
$('#mail').smartFocus(mail);
This will inject the text "* E-mail" into the element (an input or a textarea) with id='mail'
Grab