On Dec 31, 1:19 pm, Nathan Klatt <n8kl...@gmail.com> wrote:
> But, that seems like too much code for jQuery. :) I want something
> like:
>
> $someId.text(self.attr("alt"));

I've often wanted something like that too.  Unfortunately...

> This doesn't work:
>
> $someId.text($(this).attr("alt"));
>
> Does that functionality exist and I just couldn't find it in the docs?


No, and it can't be added.  This is not a problem with jQuery.  It's
intrinsic to Javascript, and in fact is the same in pretty much all
programming languages I know.  Somehow we expect all the other magic
that jQuery gives us to extend to here, but it can't.  The problem is
that  the parameters to the function text() are evaluated *before* the
function is called.  In that context, "this" cannot refer to $someId
or to a DOM node it's wrapping up, because we are not yet in such a
context.

The best we could do is to pass in a function which could then be
evaluated in the correct context.  That is what ".each()" does, as do
numerous other calls.  But they won't give you the syntactic
convenience you're looking for.

Sorry.

  -- Scott

Reply via email to