Javascript examples for DOM:Element dir
The dir property sets or gets the dir attribute of an element, which controls the text-direction of the element's content.
Set the dir property with the following Values
Value | Description |
---|---|
ltr | Default. Left-to-right text direction |
rtl | Right-to-left text direction |
auto | Let the browser figure out |
A String, representing the text writing direction of the element
The following code shows how to change the text direction of a <p> element to "right-to-left":
<!DOCTYPE html> <html> <body> <p id="myP" dir="rtl">Click the button to display my text direction.</p> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {// w w w. j a v a 2 s. co m document.getElementById("myP").dir = 'rtl'; } </script> </body> </html>