W3C DOM tests - attributes[]

Test elements

I gave the test element an event handler and an attribute I invented myself.

This is the first test element. It has the following attributes, in this order:
id="test"
align="center"
style="border: 1px solid #0000cc"
onclick="alert('Clicked!')"
ppk="JavaScript"

This is the second test element. It has only one attribute:
id="test2"

Test scripts

createAttributeList(). Creates a complete list of attributes, by index. Doesn't work in Explorer 5 Windows, though, because these browsers can't read out the name and value of the attributes.

attributes[], indexed

Test alert(x.attributes[1])
Test alert(x.attributes.length)

attributes[], keyed

Test alert(x.attributes['align'])
Test alert(x.attributes['onclick'])
Test alert(x.attributes['style'])
Test alert(x.attributes['ppk'])

name and value - attributes[]

Test alert(x.attributes[1].name)
Test alert(x.attributes[1].value)
Test alert(x.attributes[4].name)
Test alert(x.attributes[4].value)
Test alert(x.attributes['align'].value)
Test alert(x.attributes['onclick'].value)
Test alert(x.attributes['style'].value)
Test alert(x.attributes['ppk'].value)

name and value - getAttributeNode()

Test alert(x.getAttributeNode('align').value)
Test alert(x.getAttributeNode('onclick').value)
Test alert(x.getAttributeNode('style').value)
Test alert(x.getAttributeNode('ppk').value)

specified

Test alert(x.attributes['onmouseover'].specified)
Test alert(x.attributes[1].specified)