Hi Scott! Many thanks for your pro help and super fast reply! I really
appreciate it. :)

> There are a few options.  I often add an optional errorHandler
> ...<snip>...
> Then your code can check that the required parameter is there.

Oooh, that is nice! Cool technique! Thanks for sharing. :)

> Alternatively, you can simply fail silently, but merely document that
> the parameter is required.

For my simple plugin, this sounds like the most logical (and simple)
route to take.

> Absolutely, and I would recommend it.  I'd also lose the "#" and just
> add it in in the code:

Great idea. Done. :)

> Because it's the only required parameter, and in fact the only
> parameter, I would definitely treat it differently.  If you had five
> ...<snip>...
> dividing line would be, but a single mandatory parameter definitely
> falls in the simpler-is-better category.

Cool!

Ok, so how does this look:

==========

(function($) {

        //
        // Plugin definition:
        //
        $.fn.myFunction = function(id) {

                var $target = $('#' + id);

                if($target.length > 0) {

                        // Traverse all nodes:
                        return this.each(function() {

                                // Do stuff here.

                        });

                } // $target

        };

})(jQuery);

$('#div').myFunction('targ');

==========

It appears to work... Simpler than what I had before. :)

One last question:

My plugin will only be used on an #id, and the output will only
manipulate a unique #id... In other words, there will only be one
unique id in both cases. With that said, is it overkill to use
"this.each()"? If so, what is the alternative syntax?

==========

Thanks again Scott, I really appreciate the help!

Have a great day!

Cheers,
Micky

Reply via email to