Using Input Title As Initial Text - Hide When On Focus


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function watermark ($obj) {
  2.  
  3. var prev;
  4.  
  5. $obj.each(function() {
  6. if ($(this).attr("title")) $(this).val($(this).attr("title")).addClass("greyout");
  7. });
  8.  
  9. $obj
  10. .focus(function()
  11. {
  12. if ($(this).val()==$(this).attr("title")) {
  13. prev = $(this).val();
  14. $(this).val("").removeClass("greyout");
  15. }
  16. })
  17.  
  18. .blur(function()
  19. {
  20. if($(this).val()=="") {
  21. $(this).val(prev).addClass("greyout");;
  22. }
  23. });
  24.  
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.