Thank you Jules! I thought that *might* be the case, but seeing the
tell-tail jQuery code in the DHTML was a little confusing to me. But
yes, I think I understand it now. "alt" is a normal JavaScript object,
NOT jQuery. So when accessing JS objects I must always use the [0].
This also seems to apply when initializing a variable, as in

var myVariable = $("#myElement")[0];

Thanks again!



On Jul 20, 4:25 pm, Jules <jwira...@gmail.com> wrote:
> $("#myElement) returns jQuery object and $("#myElement")[0] returns
> DHTML object.
>
> Here is a sample on how to access alt attribute
> jQuery $("#myElement").attr("alt")
> vs
> DHTML $("#myElement")[0].alt
>
> Both code return the same value.  Correct me if i am wrong, I think
> the DHTML version is faster than the jQuery one.
>
> On Jul 21, 8:07 am, nyte999 <zend...@gmail.com> wrote:
>
> > Going through the tutorials on this website and others, I've found
> > some syntax that I don't understand and is never explained. Usually
> > wrapped sets look like this:
>
> > $(#myElement)
>
> > But once in a while they look like this
>
> > $(#myElement)[0]
>
> > Here are a few examples of it in use:
>
> > $("div").index($("div#myDiv")[0]);
> > $("#myImage")[0].alt;
>
> > I don't get it. The sample code is NEVER trying to find the first
> > element of an array. From my POV this format seems completely random
> > and unnecessary, yet the jQuery code will NOT work if the "[0]" is
> > removed. I know it's something glaringly obvious and I'll feel stupid
> > when I get the answer, but my god, I just can't figure out the pattern
> > here. Please help.

Reply via email to