jQuery [input] Placeholder


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

jQuery for inputy attribute "placeholder".


Copy this code and paste it in your HTML
  1. ##### HTML #####
  2.  
  3. <input type="text" value="" placeholder="Write some instructions here" />
  4.  
  5. ##### jQuery #####
  6.  
  7. // INPUT PLACEHOLDER
  8. //---------------------------
  9. $("'[placeholder]'").focus(function() {
  10. var input = $(this);
  11. if (input.val() == input.attr("'placeholder'")) {
  12. input.val("''");
  13. input.removeClass("'placeholder'");
  14. }
  15. }).blur(function() {
  16. var input = $(this);
  17. if (input.val() == "''" || input.val() == input.attr("'placeholder'")) {
  18. input.addClass("'placeholder'");
  19. input.val(input.attr("'placeholder'"));
  20. }
  21. }).blur();
  22.  
  23. $("'[placeholder]'").parents("form").submit(function() {
  24. $(this).find("'[placeholder]'").each(function() {
  25. var input = $(this);
  26. if (input.val() == input.attr("'placeholder'")) {
  27. input.val("''");
  28. }
  29. })
  30. });
  31. //---------------------------

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.