$("#warningmsg").each(highlightWarningMsg);
That would still be a bad way to do it i'd say, because if theres more than one element with the id 'warningmsg' (I know there shouldnt be, but you cant count on these things), it would fire more than once. I would just use if ($('#warningmsg')[0]).
On 1/19/07, Dave Methvin <[EMAIL PROTECTED]> wrote:
>> >> if ($('#warningmsg').size()) highlightWarningMsg(); >> >> Is that the "correct" way of testing if a jQuery object contains anything? > > You could also do: > if ($('#warningmsg')[0]) You could also say this: $("#warningmsg").each(highlightWarningMsg); Each won't call the fn at all unless the element exists. If that's the only place the fn is called, just drop an anonymous function there. Or you could turn it into a plugin and do this: $("#warningmsg").highlightMsg(); _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/
_______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/