| 1 | <html> |
|---|
| 2 | <head> |
|---|
| 3 | <title>Does getComputedStyle() work for text alignment?</title> |
|---|
| 4 | <script type="text/javascript"> |
|---|
| 5 | function getStyle(element, styleNameLong, styleNameShort) |
|---|
| 6 | { |
|---|
| 7 | if (window.getComputedStyle) |
|---|
| 8 | return window.getComputedStyle(element, "").getPropertyValue(styleNameLong); |
|---|
| 9 | else |
|---|
| 10 | return element.currentStyle[styleNameShort]; |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | function init() |
|---|
| 14 | { |
|---|
| 15 | var ids = ["test", "test2", "test3"]; |
|---|
| 16 | for(var i=0;i<ids.length;i++) |
|---|
| 17 | alert(getStyle(document.getElementById(ids[i]), "text-align", "textAlign")); |
|---|
| 18 | } |
|---|
| 19 | </script> |
|---|
| 20 | <style> |
|---|
| 21 | .rightCell {text-align: right;} |
|---|
| 22 | #justifyId {text-align: justify;} |
|---|
| 23 | </style> |
|---|
| 24 | </head> |
|---|
| 25 | <body onload="init();"> |
|---|
| 26 | <table border="1" width="100%"> |
|---|
| 27 | <tbody> |
|---|
| 28 | <tr> |
|---|
| 29 | <td align="center"> |
|---|
| 30 | <p id="test">This is a test with the traditional align attribute.</p> |
|---|
| 31 | </td> |
|---|
| 32 | </tr> |
|---|
| 33 | <tr> |
|---|
| 34 | <td class="rightCell"> |
|---|
| 35 | <p id="test2">This is a test with a style linked by class.</p> |
|---|
| 36 | </td> |
|---|
| 37 | </tr> |
|---|
| 38 | <tr> |
|---|
| 39 | <td id="justifyId"> |
|---|
| 40 | <p id="test3">This is a test with a style linked by id.</p> |
|---|
| 41 | </td> |
|---|
| 42 | </tr> |
|---|
| 43 | </tbody> |
|---|
| 44 | </table> |
|---|
| 45 | </body> |
|---|
| 46 | </html> |
|---|