Leandro,

>That said, here's how I'd simplify the plugin:
>
>jQuery.fn.defaultValue = function() {
>
>     function clearDefaultValue() {
>         var $$ = $(this);
>         if ($$.val() == this.defaultValue) { $(obj).val(''); }
>     }
>     function backDefaultValue() {
>         var $$ = $(this);
>         if ($$.val() == '') { $$.val(this.defaultValue); }
>     }
>
>     return this
>         .click(clearDefaultValue)
>       .focus(clearDefaultValue)
>       .blur(backDefaultValue);
>
>};

In addition to Klaus' comments, I'd probably rename the plug-in. The name
"defaultValue" implies to me that does something to track the original value
of a form field at page load.

However, your plug-in removes the default text when the fields receives
focus and puts it back if the user didn't put any text in the box.

Something on the lines of clearDefaultText() or resetDefaultText() I think
is more clear (not saying I love those names, but they're more specific.)

With jQuery's powerful ability to chain method calls together, I think it's
really important that method are named clearly. It can be really confusing
when revisiting code when plug-ins have confusing names.

-Dan

Reply via email to