Dave

Yes, this answer occurred to me while I was eating lunch. Oh well, I guess
it's a rite of passage to ask your first dumb question.

Thanks for your time and help. jQuery looks really very nice indeed.

Alan

-----Original Message-----
From: Dave Methvin [mailto:[EMAIL PROTECTED] 
Sent: 05 October 2006 13:07
To: [EMAIL PROTECTED]; 'jQuery Discussion.'
Subject: RE: [jQuery] Unwanted side effects when jQuery object is empty?


> $(".rounded").removeClass("rounded").wrap(env("div", "test",
{"class":"rounded"})); 

> I found that the function was being called once
> even though no html was generated. 
 
The jQuery object doesn't have any elements, but by the time the wrap method
executes it has already evaluated its arguments, which in this case includes
your env() function. The env() executes once, only once, and always once, no
matter how many elements the jQuery object has selected.

> I can avoid the problem by rewriting the code as something like 
>
$(".rounded").removeClass("rounded").each(function(){$(this).wrap(env("div",
"test", {"class":"rounded"}))}); 

Right, because the anonymous function will be executed once for each element
in the jQuery object.



_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to