From: Ry Nohryb on
On Jul 4, 6:42 pm, William Gill <nos...(a)domain.invalid> wrote:
> I am working on a snippet and in my research I see that the options
> property of the select object is a collection, not an array.  I am
> having great difficulty finding any good, comprehensive documentation on
> javascript collections and their methods. Can anyone point me to a good
> reference?
>

The most important difference between a JS array and a DOM collection
is that collections -unlike arrays- are live:

var collection= document.getElementsByTagName('div');
var item1= collection[collection.length-1];
document.body.appendChild(document.createElement('div'));
var item2= collection[collection.length-1];

item1 === item2
--> false

--
Jorge.
From: Ry Nohryb on
On Jul 7, 10:26 am, Ry Nohryb <jo...(a)jorgechamorro.com> wrote:
> On Jul 4, 6:42 pm, William Gill <nos...(a)domain.invalid> wrote:
>
> > I am working on a snippet and in my research I see that the options
> > property of the select object is a collection, not an array.  I am
> > having great difficulty finding any good, comprehensive documentation on
> > javascript collections and their methods. Can anyone point me to a good
> > reference?
>
> The most important difference between a JS array and a DOM collection
> is that collections -unlike arrays- are live:
>
> var collection= document.getElementsByTagName('div');
> var item1= collection[collection.length-1];
> document.body.appendChild(document.createElement('div'));
> var item2= collection[collection.length-1];
>
> item1 === item2
> --> false

Also:

var c1= document.getElementsByTagName('div');
var c2= document.getElementsByTagName('div');
c1 === c2
--> true

--
Jorge.
From: Richard Cornford on
On Jul 7, 9:33 am, Ry Nohryb wrote:
<snip>
> Also:
>
> var c1= document.getElementsByTagName('div');
> var c2= document.getElementsByTagName('div');
> c1 === c2
> --> true

That is extremely unlikely to hold in all environments, and there is
no technical reason to expect that it would. It is not a relationship
that should be relied upon, probably even in a (semi-)controlled
environment such as an Intranet.

Richard.
From: William Gill on
On 7/4/2010 8:27 PM, RobG wrote:

>>> I am having
>>> great difficulty finding any good, comprehensive documentation on
>>> javascript collections and their methods. Can anyone point me to a good
>>> reference?
>>
>> There are not too many properties or methods.
>>
>> For a start:https://developer.mozilla.org/En/DOM/NodeList
>
> The definitive reference is the W3C DOM Core spec, the above page has
> a link to the DOM 3 Core reference, which doesn't seem to have changed
> since Level 1.
>
> However, the OP was asking about collections, which are a type of
> NodeList that have some extra features:
>
> DOM 2 HTMLCollection
> <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506>
>
> DOM 2 introduced the HTMLOptionsCollection interface, which is similar
> to other collections but differs in that the namedItem method accepts
> only an id and that length is not readonly, so it can be used to set
> the number of items (e.g. as a quick way to remove all options, set
> length to zero):
>
> DOM 2 HTMLOptionsCollection
> <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#HTMLOptionsCollection
>>
>
> The relevant HTML5 reference is:
> <URL: http://www.w3.org/TR/html5/common-dom-interfaces.html#collections-0
>>
>
Thanks Rob, and everyone. Good starting point. The DOM core refs I
have, though searchable (pdf) didn't help too much.
From: Garrett Smith on
On 2010-07-06 11:25 PM, RobG wrote:
> On Jul 7, 9:48 am, Garrett Smith<dhtmlkitc...(a)gmail.com> wrote:
>> On 2010-07-06 09:41 AM, Dr J R Stockton wrote:

[...]

>> "1.3 How can I post to comp.lang.javascript"
>>
>> It is best to post through a newsreader, such as Thunderbird.
>
> I have a mostly hate relationship with Thunderbird. It's newsgroup
> filtering leaves a lot to be desired - why can't I run a filter on
> messages that have already arrived?
>
> Anyhow, I find it pretty useless as a news reader and there aren't any
> others worth using on Mac OS. Perhaps I'll switch to a Windows-based
> agent.
>

OK, TB's at least better than GG I hope. What other readers are worth
recommending? Would a list of two or three be right for the FAQ?

--
Garrett