HTML DOM dirProperty
Definition and Usage
The dir property sets or returns the text direction of an element.
Syntax
HTMLElementObject.dir=text-direction
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the dir property
Example
Example
Return the text direction of the body element:
<html>
<body id="myid" dir="rtl">
<script>
var x=document.getElementsByTagName('body')[0];
document.write("Text direction: " + x.dir);
document.write("<br>");
document.write("An alternate way: ");
document.write(document.getElementById('myid').dir);
</script>
</body>
</html>
<body id="myid" dir="rtl">
<script>
var x=document.getElementsByTagName('body')[0];
document.write("Text direction: " + x.dir);
document.write("<br>");
document.write("An alternate way: ");
document.write(document.getElementById('myid').dir);
</script>
</body>
</html>
Try it yourself »
Other Extensions
Element Object