/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Remove and restore the defaultValue from a text input or textarea if it is unchanged. */ (function ($) { $.fn.defaultvalue = function () { var els = $(this).filter("textarea,input[type=text]"); return els.each(function () { var el = $(this); var dv = el.attr("defaultValue"); el.focus(function () { if (el.attr("value") == dv) { el.attr("value", "") } }).blur(function () { if (el.attr("value") == "") { el.attr("value", dv) } }) }) } })(jQuery);
Comments
