In this section, we will learn what the Element dir property is and how to use it in JavaScript.
What is Element dir Property in JavaScript?
The JavaScript Element dir property is used to set or get the value of the dir attribute (reading order) of an HTML element.
Element dir Property Syntax:
element.dir; element.dir = newValue;
Element dir Property Input Value
The value we set for this property is the same as those that we could use for the dir attribute.
These values are:
“ltr”: which means left-to-right text direction.
“rtl”: which means right to left text direction.
“auto”: this is the default value and means the browsers should decide the direction by itself.
Element dir Property Return Value
The return value of this property is the current value set for the target element’s dir attribute.
Note: if this attribute is not set for the target element, the return value will be an empty string.
Example: using dir Property in JavaScript
See the Pen using dir Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.