Forked from hagenburger/jQuery HTML5 placeholder fix.js
Created
October 27, 2011 20:47
-
-
Save pjeweb/1320822 to your computer and use it in GitHub Desktop.
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 | |
// good javascript | |
(function ($) { | |
'use strict'; | |
$(function () { | |
$('[placeholder]') | |
.focus(function () { | |
var input = $(this); | |
if (input.val() === input.attr('placeholder')) { | |
input.val('').removeClass('placeholder'); | |
} | |
}) | |
.blur(function () { | |
var input = $(this); | |
if (input.val() === '' || input.val() === input.attr('placeholder')) { | |
input.addClass('placeholder').val(input.attr('placeholder')); | |
} | |
}) | |
.blur() | |
.parents('form').submit(function () { | |
$(this).find('[placeholder]').each(function () { | |
var input = $(this); | |
if (input.val() === input.attr('placeholder')) { | |
input.val(''); | |
} | |
}); | |
}); | |
}); | |
})(jQuery); | |
// minified javascript | |
(function(j,p){j(function(){j("["+p+"]").focus(function(){var i=j(this);if(i.val()===i.attr(p)){i.val("").removeClass(p)}}).blur(function(){var i=j(this);if(i.val()===""||i.val()===i.attr(p)){i.addClass(p).val(c.attr(p))}}).blur().parents("form").submit(function(){j(this).find(p).each(function(){var i=j(this);if(i.val()===i.attr(p)){i.val("")}})})})})(jQuery,"placeholder"); |
Doesn't seem to work properly when using the HTML5 required attribute.
Awesome!! Thanks @rozboris
Shouldn't the placeholder be whatever you define, "Password" rather than "********"? How to accomplish that?
This is not working with ie8 for me.
Edit: Correction. It must be getting wiped out by the json in ie8/9 which is not an issue in 10+. Ugh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. https://gist.github.com/379601 wasn't working in IE8.