Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  This JQuery code will essentially display a background text hint/label in all input boxes marked with class .background-text when they are empty. The style of an "empty" box is defined by the .empty class (you can, for example, set a dark gray color here). The "background text" is taken from the 'title' attribute of the input tag. If you leave the 'value' attribute empty, the script will degrade invisibly (nothing happens) when the user does not have Javascript support enabled.
  2.  
  3.  
  4. $('.background-text').each(function(i,el){
  5.         $(el).addClass("empty");
  6.         el.value = el.title;
  7.         $(el).focus(function(){
  8.             if($(el).hasClass("empty"))
  9.             {
  10.                 el.value = "";
  11.                 $(el).removeClass("empty");
  12.             }
  13.         });
  14.         $(el).blur(function(){
  15.             if(el.value == "")
  16.             {
  17.                 el.value = el.title;
  18.                 $(el).addClass("empty");
  19.             }
  20.         });
  21.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement