/ Published in: jQuery

A jQuery snippet to make form inputs show a help message which disappears on click (and comes back when the user enters nothing). Give your input the classes ‘remember’ to activate the snippet and (optionally) ‘unfocused’ as a CSS hook for changing the styling of the help message.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var origValue = []; $('input.remember').each ( function (currentIndex) { origValue.push ( $(this).val () ); $(this).focus ( function () { $(this).removeClass("unfocused"); var defaultText = $(this).val(); if ( $(this).val () == origValue [ currentIndex ] ) { $(this).val(''); } $(this).blur(function() { var userInput = $(this).val(); if (userInput == '') { $(this).val(defaultText); $(this).addClass("unfocused"); } }); }); });
Comments
