Taken loosely from:
http://www.quirksmode.org/dom/getstyles.html
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body {
direction: rtl;
}
</style>
<script type="text/javascript">
function getStyle(el,styleProp)
{
var x = document.getElementById(el) || document.body;
if (x.currentStyle)
var y = x.currentStyle[styleProp];
else if (window.getComputedStyle)
var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
return y;
}
onload = function(){alert(getStyle(null, 'direction'));};
</script>
</head>
<body>
Hi
</body>
</html>
Notes: This will even work if the direction hasn't been set, returning the default (ltr), or if it is set using the dir attribute, returning whatever the computed style direction is for the element. For style properties that contain hyphens, the camel style notation would be required for half of the getStyle function. So, if you intend to use this for other properties (direction is safe because it's all one word) you may have to deal the the camel/hyphen issue.
Bookmarks