I'm a very green jQuery user, so apologies if I've missed something obvious …
I have a line of code that reads
$(".rounded").removeClass("rounded").wrap(env("div", "test", {"class":"rounded"}));
env() is a function that (with these parameters) generates the string '<div class="rounded">test</div>'.
The intention is that, for any element with class 'rounded', that class is removed from the element, and the element is wrapped by the given div.
This works fine when there are one or more elements with class 'rounded'. It also seems to work fine when there are no such elements, but when I (for some another reason) put a diagnostic alert into env(), I found that the function was being called once even though no html was generated.
I can avoid the problem by rewriting the code as something like
$(".rounded").removeClass("rounded").each(function(){$(this).wrap(env("div", "test", {"class":"rounded"}))});
That seem a bit of a shame. Or I can avoid it by not having side effects in my functions - usually a good idea, but I was surprised that the function was called at all.
Any insights?
Alan Williams
_______________________________________________ jQuery mailing list [email protected] http://jquery.com/discuss/
