Latest web development tutorials

HTML DOM dir attribute

Elements Object Reference Element object


Definition and Usage

dir property sets or returns the direction of text elements.

grammar

HTMLElementObject.dir=text-direction


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the dir attribute


Examples

Examples

Returns 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>

try it"


Elements Object Reference Element object