make HTML5 placeholders work in non supportive browsers


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

make HTML5 placeholders work in non supportive browsers


Copy this code and paste it in your HTML
  1. // make HTML5 placeholders work in non supportive browsers
  2. $("input[placeholder]").each(function(){
  3. if($(this).val()==""){
  4. // $(this).addClass('hasplaceholder');
  5. $(this).val($(this).attr("placeholder"));
  6. $(this).focus(function(){
  7. if($(this).val()==$(this).attr("placeholder")) $(this).val("");
  8. // $(this).removeClass('hasplaceholder');
  9. });
  10. $(this).blur(function(){
  11. if($(this).val()==""){
  12. // $(this).addClass('hasplaceholder');
  13. $(this).val($(this).attr("placeholder"));
  14. }
  15. });
  16. }
  17. });
  18.  
  19. $('form').submit(function(evt){
  20. $('input[placeholder]').each(function(){
  21. if($(this).attr("placeholder") == $(this).val()) {$(this).val('');}
  22. });
  23. });
  24. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.