/* Fake the placeholder attribute since Firefox doesn't support it. */ jQuery.fn.placeholder = function(new_value) { if (new_value) { this.attr('placeholder', new_value); } /* Bail early if we have built-in placeholder support. */ if ('placeholder' in document.createElement('input')) { return this; } if (new_value && this.hasClass('placeholder')) { this.val('').blur(); } return this.focus(function() { var $this = $(this), text = $this.attr('placeholder'); if ($this.val() == text) { $this.val('').removeClass('placeholder'); } }).blur(function() { var $this = $(this), text = $this.attr('placeholder'); if ($this.val() == '') { $this.val(text).addClass('placeholder'); } }).each(function(){ /* Remove the placeholder text before submitting the form. */ var self = $(this); self.closest('form').submit(function() { if (self.hasClass('placeholder')) { self.val(''); } }); }).blur(); }; $("input[placeholder]").placeholder();