The dir
property sets or returns the text-direction for an element.
HTMLElementObject.dir=text-direction
dir |
Yes | Yes | Yes | Yes | Yes |
The following code shows how to get the text direction for the body element.
<!DOCTYPE html>
<html>
<body id="myid" dir="rtl">
<!-- ww w. java2 s . c om-->
<script>
var x=document.getElementsByTagName('body')[0];
document.write("Text direction: " + x.dir);
document.write("<br/>");
document.write(document.getElementById('myid').dir);
</script>
</body>
</html>
The code above is rendered as follows: