Advertisement
firoze

placeholder textarea IE support js

Jan 3rd, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. // placeholder IE support js
  2. jQuery(function() {
  3.    jQuery.support.placeholder = false;
  4.    webkit_type = document.createElement('input');
  5.    if('placeholder' in webkit_type) jQuery.support.placeholder = true;});
  6.    $(function() {
  7.  
  8.      if(!$.support.placeholder) {
  9.  
  10.        var active = document.activeElement;
  11.  
  12.        $(':text, textarea, :password').focus(function () {
  13.  
  14.        if (($(this).attr('placeholder')) && ($(this).attr('placeholder').length > 0) &&         ($(this).attr('placeholder') != '') && $(this).val() == $(this).attr('placeholder')) {
  15.           $(this).val('').removeClass('hasPlaceholder');
  16.         }
  17.       }).blur(function () {
  18. if (($(this).attr('placeholder')) && ($(this).attr('placeholder').length > 0) &&  ($(this).attr('placeholder') != '') && ($(this).val() == '' || $(this).val() ==   $(this).attr('placeholder'))) {
  19.      $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
  20. }
  21. });
  22.  
  23. $(':text, textarea, :password').blur();
  24. $(active).focus();
  25. $('form').submit(function () {
  26.      $(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
  27. });
  28. }
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement