bind events overwriting themselves when called more than once through a jquery plugin
Here is my function.
- $.fn.textReplace = function(options) {
- var defaults = {
- text: "enter text"
- };
- var options = $.extend(defaults, options);
- return this.each(function() {
- obj = $(this);
- if(obj.val() == '') {
- obj.val(options.text);
- } else {
- options.text = obj.val();
- }
- obj.bind({
- focus: function() {
- if(obj.val() == options.text) { obj.val(""); }
- },
- focusout: function() {
- if(obj.val() == "") { obj.val(options.text); }
- }
- });
- });
- };
If I call say:
- $('input#email').textReplace({text:"your email address"});
- $('input#zip').textReplace({text:"your zip code"});
Only the zip field will toggle the text.
My question is: How do I fix the plugin so that the events don't overwrite eachother?
Thanks for any insight!