| <html> |
| <head> |
| <title>setAttribute() Test</title> |
| |
| <style type="text/css" title="text/css"> |
| |
| p { display:none; color: red; } |
| p[title] { display:block; color: green; } |
| p[id] { display:block; color: green; } |
| p[class] { display:block; color: green; } |
| p[lang] { display:block; color: green; } |
| |
| </style> |
| |
| <script type="text/javascript"> |
| window.onload = init; |
| |
| function init() |
| { |
| document.getElementsByTagName('p')[0].setAttribute('class','test'); |
| document.getElementsByTagName('p')[1].setAttribute('id','test'); |
| document.getElementsByTagName('p')[2].setAttribute('title','This is a test'); |
| document.getElementsByTagName('p')[4].setAttribute('lang','en'); |
| } |
| </script> |
| |
| </head> |
| <body> |
| <h1>setAttribute() Test</h1> |
| <p> |
| This element's Class attribute is set using setAttribute(). It should be green. |
| </p> |
| <p> |
| This element's ID attribute is set using setAttribute(). It should be green. |
| </p> |
| <p> |
| This element's Title attribute is set using setAttribute(). It should be green. |
| </p> |
| <p title="This is hard-coded"> |
| This element's Title attribute is hard-coded. It should be green. |
| </p> |
| <p> |
| This element's Lang attribute is set using setAttribute(). It should be green. |
| </p> |
| </body> |
| </html> |