Skip to content

Instantly share code, notes, and snippets.

@gpluess
Created August 13, 2012 14:50
Show Gist options
  • Save gpluess/3341427 to your computer and use it in GitHub Desktop.
Save gpluess/3341427 to your computer and use it in GitHub Desktop.
Placeholder attribute for older browsers
// only bind if placeholder isn't natively supported by the browser
if (!('placeholder' in input)) {
$('input[placeholder]').each(function () {
'use strict';
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);
}
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment