W3C DOM tests - attribute basics

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

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

This page contains test cases for basic attribute functionality.

Other attribute tests:

Test scripts

getAttribute()

This method is supposed to return the value of the attribute.

alert(x.getAttribute('align'))
alert(x.getAttribute('ppk'))
alert(x.getAttribute('onclick'))
alert(x.getAttribute('style'))

And a test with UPPER CASE attribute names:

alert(x.getAttribute('ALIGN'))
alert(x.getAttribute('PPK'))

setAttribute()

x.setAttribute('align','right')

This style change should make the text green and make the border disappear.

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

removeAttribute()

x.removeAttribute('style')
x.removeAttribute('align')
x.removeAttribute('onclick')