jQuery Version: 1.4.1
I am attempting to write a simple watermark type plugin and I want to take advantage of live events since not all of the elements I need to use it on will exist during the page load, or they may be added and removed from the DOM. However, for some reason the events never fire.
Here is the not working code:
; (function($) {
$.fn.watermark = function(text) {
return $(this).each(function() {
$(this).live('focusout', function() {
if (this.value == "") {
this.value = text;
}
return false;
});
$(this).live('focusin', function() {
if (this.value == text) {
this.value = "";
}
return false;
});
});
}
})(jQuery);
I can get this to work without using live events. This code does work:
; (function($) {
$.fn.watermark = function(text) {
return $(this).each(function() {
$(this).focusout(function() {
if (this.value == "") {
this.value = text;
}
return false;
});
$(this).focusin(function() {
if (this.value == text) {
this.value = "";
}
return false;
});
});
}
})(jQuery);