Posted By

terrencewood on 07/31/10


Tagged

jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sales2u


jquery.defaultvalue


 / Published in: JavaScript
 

  1. /**
  2.  * Remove and restore the defaultValue from a text input or textarea if it is unchanged.
  3.  */
  4. (function ($) {
  5. $.fn.defaultvalue = function () {
  6. var els = $(this).filter("textarea,input[type=text]");
  7. return els.each(function () {
  8. var el = $(this);
  9. var dv = el.attr("defaultValue");
  10. el.focus(function () {
  11. if (el.attr("value") == dv) {
  12. el.attr("value", "")
  13. }
  14. }).blur(function () {
  15. if (el.attr("value") == "") {
  16. el.attr("value", dv)
  17. }
  18. })
  19. })
  20. }
  21. })(jQuery);

Report this snippet  

You need to login to post a comment.