Forked from hagenburger/jQuery HTML5 placeholder fix.js
Last active
December 14, 2015 16:19
-
-
Save akeemw/5114232 to your computer and use it in GitHub Desktop.
A fork of a fork found elsewhere on the Interwebs. Major difference here from other forks is that the .blur() is removed because it causes issues with JS validation scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php | |
var input = document.createElement("input"); | |
if(('placeholder' in input) == false) { | |
$('[placeholder]') | |
.each(function(){ | |
var i = $(this); | |
if(i.val() == '' || i.val() == i.attr('placeholder')) { | |
if(this.type=='password') { | |
i.addClass('password'); | |
this.type='text'; | |
} | |
i.addClass('placeholder').val(i.attr('placeholder')); | |
} | |
}) | |
.focus(function() { | |
var i = $(this); | |
if(i.val() == i.attr('placeholder')) { | |
i.val('').removeClass('placeholder'); | |
if(i.hasClass('password')) { | |
i.removeClass('password'); | |
this.type='password'; | |
} | |
} | |
}) | |
.blur(function() { | |
var i = $(this); | |
if(i.val() == '' || i.val() == i.attr('placeholder')) { | |
if(this.type=='password') { | |
i.addClass('password'); | |
this.type='text'; | |
} | |
i.addClass('placeholder').val(i.attr('placeholder')); | |
} | |
}) | |
.parents('form').submit(function() { | |
$(this).find('[placeholder]').each(function() { | |
var i = $(this); | |
if(i.val() == i.attr('placeholder')) | |
i.val(''); | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment