HTML DOM Element dir attribute
- Previous Page contentEditable
- Next Page firstChild
- Go Up One Level HTML DOM Elements Object
Definition and usage
dir
Attribute sets or returns the element's dir attribute.
dir
Attribute defines text direction.
See also:
Example
Example 1
Change the text direction of "myP" to "right-to-left":
document.getElementById("myP").dir = "rtl";
Example 2
Return the text direction of the document:
document.body.dir;
Example 3
Set the text direction of the document:
document.body.dir = "rtl";
Syntax
Return dir attribute:
element.dir
Set dir attribute:
element.dir = "ltr|rtl|auto"
Attribute value
Value | Description |
---|---|
ltr | Left-to-right text direction (default). |
rtl | Right-to-left text direction. |
auto | Let the browser determine. |
Return value
Type | Description |
---|---|
String | the text direction of the element. |
Browser support
All browsers support element.dir
:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | Support | Support | Support | Support | Support |
- Previous Page contentEditable
- Next Page firstChild
- Go Up One Level HTML DOM Elements Object