Javascript Reference - HTML DOM dir Property








The dir property sets or returns the text-direction for an element.

Syntax

HTMLElementObject.dir=text-direction

Browser Support

dir Yes Yes Yes Yes Yes

Example

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: