In the meantime, I changed the wording on that page.

Both of the following will work:
1)
return this.each(function() { /* do something */ });
2)
this.each(function() { /* do something */ });
return this;

--Karl

On Nov 8, 2009, at 12:56 PM, Morten Maxild wrote:

Exactly...looks correct:-)

-----Original Message-----
From: Shane Riley [mailto:shanerileydoti...@gmail.com]
Sent: Sunday, November 08, 2009 6:44 PM
To: jQuery (English)
Subject: [jQuery] Re: Plugin Authoring Code Example Incorrect

I ended up using this syntax instead:
return this.each(function(){});

On Nov 7, 11:43 am, "Morten Maxild" <mmax...@gmail.com> wrote:
'return true' is wrong, you need to return the 'wrapped set' to support
chaining. The $().each method does return the 'wrapped set' and you can
take advantage of this.

HTH
Morten



-----Original Message-----
From: Shane Riley [mailto:shanerileydoti...@gmail.com]
Sent: Saturday, November 07, 2009 1:19 PM
To: jQuery (English)
Subject: [jQuery] Plugin Authoring Code Example Incorrect

I created a jQuery plugin for the sake of learning the process and got
it working no problem. In the plugin authoring docs it says that if
you return true inside the each method, you can continue using jQuery chaining. However the code example above has the return this statement at the end of the plugin function rather than the each method. While
quickly reading through this article after creating my plugin to
ensure I was following best practices, I placed the return true in the
same spot and my Javascript ceased to run. I tried logging in and
editing the documentation, however it's locked. Just wanted to let
everyone know of the mistake in the hopes someone on here has the
ability to fix it.


Reply via email to