VK wrote:
[color=blue]
>
mumrah@gmail.com wrote:[color=green]
>> So if i'm parsing through the DOM, and i have some parents and i access
>> it's children:
>>
>> object.childNodes
>>
>> I should access the children via [0] and not item(0) ?[/color][/color]
It is virtually the same in an HTML 4.01/XHTML 1.0 context.
Whether or not the former should be used depends on the context.
[color=blue][color=green]
>> example: document.getElementById('foo').childNodes[0] as opposed to
>> document.getElementById('foo').childNodes.item(0)
>>
>> I had always used the [] to access array elements in JS until i
>> starting writing this program that has to parse through an xml dom.[/color][/color]
The XML DOM is not DOM Level 2 _HTML_. The property accessor method is
defined for that DOM which applies to HTML 4.01 and XHTML 1.0 documents
only.
[color=blue][color=green]
>> The site that i read up on that topic used to item() method so,
>> naturally, i used it as well. But i'm happy to change back to using
>> brackets. less typing :)[/color]
>
> item() is Microsoft method, maybe someone else accepted it either,[/color]
Wrong. item() as used here is a method of DOM Level 2 HTML's HTMLCollection
interface. Using the property accessor syntax with a numeric parameter is
the same as calling this method:
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506>
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecmascript-binding.html>
[color=blue]
> but the most universal way is collection[i][/color]
What is to be noted is that access methods of the W3C DOM tend to be poorly
implemented [ref. Element::setAttribute()], therefore the property accessor
syntax /may be/ the more reliable one, the _proper_ context provided (see
above). It also is less error-prone _there_ because property accessor
syntax is a feature of the programming language, while a method of DOM
objects is a feature of the DOM -- the method call fails with a
ReferenceError if the method is not supported, the property accessor syntax
will not (unless that expression is used untested as base reference for
another property access).
[color=blue]
> Some IE-specific collections are locked for conventional use: you have
> to wrap them into Microsoft Enumerator object first. These are for
> example file/folder collections returned by FileSystemObject. But in
> regular DOM brackets are more reliable in all curcumstances.[/color]
You are confusing languages (here: JScript, VBScript) and AOM/DOM. Again.
PointedEars