HTML5 Placeholder Jquery fix


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



Copy this code and paste it in your HTML
  1. var input = document.createElement("input");
  2. if(('placeholder' in input)==false) {
  3. $('[placeholder]').focus(function() {
  4. var i = $(this);
  5. if(i.val() == i.attr('placeholder')) {
  6. i.val('').removeClass('placeholder');
  7. if(i.hasClass('password')) {
  8. i.removeClass('password');
  9. this.type='password';
  10. }
  11. }
  12. }).blur(function() {
  13. var i = $(this);
  14. if(i.val() == '' || i.val() == i.attr('placeholder')) {
  15. if(this.type=='password') {
  16. i.addClass('password');
  17. this.type='text';
  18. }
  19. i.addClass('placeholder').val(i.attr('placeholder'));
  20. }
  21. }).blur().parents('form').submit(function() {
  22. $(this).find('[placeholder]').each(function() {
  23. var i = $(this);
  24. if(i.val() == i.attr('placeholder'))
  25. i.val('');
  26. })
  27. });
  28. }
  29. });
  30. /* ]]> */

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.