[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread Michael Geary
> > > $('#foo')[0] > > >Will throw error if there is no match, IIRC. > > No, it won't. It is not an error to fetch a nonexistent > > array element > Thanks for a nice explanation. I'm sorry for jumping > without reading it properly. Glad to help - but no apology needed! You should see

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread R. Rajesh Jeba Anbiah
On Aug 16, 8:55 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > > > I've been hacking with jQuery on and off lately and I've > > > now hit the annoying problem of not being able to access > > > simple DOM 0 properties unless, apparently, using either > > > of the following syntaxes: > > > > $('#f

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread Michael Geary
> > I've been hacking with jQuery on and off lately and I've > > now hit the annoying problem of not being able to access > > simple DOM 0 properties unless, apparently, using either > > of the following syntaxes: > > > > $('#foo')[0] >Will throw error if there is no match, IIRC. No, it won

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread Erik Beeson
The point is to get the first DOM node, so you'd still need to do [0], which would still throw an error if there was no match. If you're not certain that there'll be a match, maybe something like this would be safer: var $foo = $('#foo'); if($foo.length > 0) { var foo = $foo[0]; } else { // n

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread R. Rajesh Jeba Anbiah
On Aug 15, 11:29 am, pd <[EMAIL PROTECTED]> wrote: > I've been hacking with jQuery on and off lately and I've now hit the > annoying problem of not being able to access simple DOM 0 properties > unless, apparently, using either of the following syntaxes: > > $('#foo')[0] Will throw error if th

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-16 Thread wick
> It seems more intuitive and consistent than: > > $('#foo')[0].className; > $('#foo')[0].size; > $('#foo')[0].type; If you're repeatedly accessing the first DOM object of a jQuery selector array, it's a good practice to set a variable: var myObject = $('#foo')[0]; ..then you can access DOM pro

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Erik Beeson
http://docs.jquery.com/DOM/Attributes#Attr --Erik On 8/15/07, pd <[EMAIL PROTECTED]> wrote: > > > 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 synt

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread pd
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'); $('#fo

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Erik Beeson
Uh, thanks, you flatter me, but I'm not one of the people that edit the wiki. I think it would be sweet if the web team got in touch with Simon and asked him if we could pull that article into docs.jquery.com as an official jQuery Primer. I think it focuses on the right introductory aspects of jQue

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread pd
Thanks Eric I'll remember to consider jQuery selector results an array from now on. So, do you feel like updating the wiki? Sounds like you would be the best person to do so as your understanding appears quite deep. I had a look at Mr Willison's article yesterday but only got half way through b

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Erik Beeson
> 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 wit

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread pd
Hi All, Thanks for the responses. Firstly, everyone is assuming I am referring to an array. Not necessarily the case. In fact in a legit XHTML 1.0 Strict document an 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 obje

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Michael Geary
> From: pd > > I've been hacking with jQuery on and off lately and I've now > hit the annoying problem of not being able to access simple > DOM 0 properties unless, apparently, using either of the > following syntaxes: > > $('#foo')[0] > > $('#foo').get(0) pd, just to help clarify... The $(

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Michael Geary
> > From: Erik Beeson > > The [n] syntax is just a shortcut for > > .get(n):http://docs.jquery.com/Core#get.28_num_.29 > From: Gordon > > I would imagine that the [] syntax would be a bit faster than the > get() syntax, on the grounds that the former is simply > addressing an array, whereas th

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Klaus Hartl
gradez28 wrote: Just curious, how exactly do you expect to be able to access a 0 object? Are you thinking you can go: object.0.function()? If so, regardless of how cool jQuery is, when an array's key uses numerics, you simpy cannot access it as an object because objects must start with an alpha

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread gradez28
Just curious, how exactly do you expect to be able to access a 0 object? Are you thinking you can go: object.0.function()? If so, regardless of how cool jQuery is, when an array's key uses numerics, you simpy cannot access it as an object because objects must start with an alpha character. I dont

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-15 Thread Gordon
I would imagine that the [] syntax would be a bit faster than the get() syntax, on the grounds that the former is simply addressing an array, whereas the latter is calling a function and getting the returned result. I'll have to try benchmarking them in a loop when I've got some free time. On Au

[jQuery] Re: Documentation on $('#foo')[0] or $('#foo').get(0) ??

2007-08-14 Thread Erik Beeson
var a = $(...); var b = a.length; a.XXX(); var c = a.get(0); Now, 'a' is a "jQuery object" that contains all of the elements that matched the selector. 'b' is the number of elements found. The third line is calling a jQuery function or plugin on the jQuery object that is wrapping the selected elem