Use the html5 placeholder attribute now
Until the html5 placeholder attribute works on Gecko or IE browsers, you can use this following jQuery code.
// 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="">
Detection method is picked up from diveintohtml5.org