Futher to this overall topic Eric, do you think it would be possible/
wise to implement a jQuery method that returns any of the standard DOM
properties? I'm just wishlisting but I think this syntax (each line a
different example property):

$('#foo').dom('className');
$('#foo').dom('size');
$('#foo').dom('type');

would be very intuitive for developers and very consistent with the
rest of the jQuery library.

It seems more intuitive and consistent than:

$('#foo')[0].className;
$('#foo')[0].size;
$('#foo')[0].type;

to me, though maybe the method name of dom() is not the most clear and
or explicit. It is short though :)

pd

On Aug 16, 11:27 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
> > id is supposed to be unique is it not? My example used the # to refer
> > to a unique id on the page, therefore *not* an array of objects.
>
> Wrong, it *is* still an array of objects, it's just an array of length
> 1. Do console.log($('#foo')) and you'll see that it is still an array,
> and an array with one object in it is not the same as the object
> itself.
>
> > AFAIK all three examples get an element on the page as a *single* (not
> > an array) object.
>
> And that's wrong. The jQuery object is always an array. It's of length
> 0 for no matches, 1 for a single match, or more for multiple matches.
> That's by design, so that the chaining things work consistently. This
> allows you to make chained calls that won't throw an error, regardless
> of whether or not the selector found anything.
>
> > I think it's reasonable (though perhaps not programmatically correct)
> > to see $('#foo') as the equivalent of document.getElementById('foo').
> > If this is not true in jQuery, which it does not appear to be, all I
>
> Right, it's not.
>
> > am saying is this distinction should be clearly documented.
>
> Agreed. This should probably be made clearer. I think the recently
> discussed post by Simon Willison addresses this really well (under
> "Doing stuff with them"):http://simonwillison.net/2007/Aug/15/jquery/
>
> --Erik

Reply via email to