Set the text direction of a <p> element to "right-to-left":
document.getElementById("myP").style.direction = "rtl";
<!DOCTYPE html> <html> <body> <p id="myP">This is an example paragraph.</p> <button type="button" onclick="myFunction()">Let text flow from right to left</button> <script> function myFunction() {/*from w w w . j av a2s . c o m*/ document.getElementById("myP").style.direction = "rtl"; } </script> </body> </html>
The direction property sets or gets the reading order of an element's content.
Property Values
Value | Description |
---|---|
ltr | Text flows from left to right. default |
rtl | Text flows from right to left |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The direction property returns a String representing the text direction of an element.