W3C DOM tests - attributes[]

  • When tested very extensively Opera may eventually crash.
  •  

    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"

     

    var x,y,z;
    window.onload = function () {
    	x = document.getElementById('test');
    	y = document.getElementById('test2');
    }
    

    Attribute properties:
    Test alert(x.attributes[1])
    Test alert(x.attributes[1].name)
    Test alert(x.attributes[1].value)
    Test alert(x.attributes.length)
    Test alert(x.attributes[4].value)

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

    Microsoft attribute methods:
    Test x.clearAttributes()
    Test y.mergeAttributes(x)

    Creating attributes: (title attribute is not added by any browser)
    Test z = document.createAttribute('title','Test Title')
    Test x.setAttributeNode(z)
    Check it: alert(x.attributes['title'].value)
    Check it: alert(x.attributes[5].value)

    Attribute methods:
    Test alert(x.getAttribute('align'))
    Test alert(x.getAttribute('ppk'))
    Test alert(x.getAttribute('onclick'))
    Test alert(x.getAttribute('style'))
    Test alert(x.getAttributeNode('align'))
    Test alert(x.getAttributeNode('align').value)

    Test x.removeAttribute('style')
    Test x.removeAttribute('align')
    Test x.removeAttribute('onclick')
    Test x.removeAttributeNode(x.attributes['align'])
    Test x.removeAttributeNode(x.attributes[1])

    Test x.setAttribute('align','right')
    Test x.setAttribute('style','color: #00cc00')
    Test x.setAttribute('onclick','alert("Changed onclick")')
    Test x.setAttribute('ppk','Noscript')

    Related methods:
    Test alert(x.hasAttribute('align'))
    Test alert(x.hasAttribute('class'))
    Test alert(x.hasAttribute('ppk'))
    Test alert(x.hasAttribute('onclick'))
    Test alert(x.hasAttributes())