Created
June 5, 2012 20:30
-
-
Save ixzy24/2877608 to your computer and use it in GitHub Desktop.
html5 placeholder fallback
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
// jQuery code | |
var i = document.createElement("input"); | |
// Only bind if placeholder isn't natively supported by the browser | |
if (!("placeholder" in i)) { | |
$("input[placeholder]").each(function () { | |
var self = $(this); | |
self.val(self.attr("placeholder")).bind({ | |
focus: function () { | |
if (self.val() === self.attr("placeholder")) { | |
self.val(""); | |
} | |
}, | |
blur: function () { | |
var label = self.attr("placeholder"); | |
if (label && self.val() === "") { | |
self.val(label); | |
} | |
} | |
}); | |
}); | |
} | |
<!-- html5 --> | |
<input type="text" name="search" placeholder="Search" value=""> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment