JavaScript element.dir Property
You are Here:
JavaScript element.dir Property
The element.dir
property gets or sets the text writing directionality of the content of the current element.
Get Direction
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p dir="ltr">Click on the button.</p>
<button onclick="myFunction()">Click Me</button>
<p id="point"></p>
<script>
var x = document.getElementById("point");
var elem = document.getElementsByTagName("p")[0];
function myFunction(){
x.innerHTML = elem.dir;
}
</script>
</body>
</html>
Syntax
element.dir
Return Values
Value | Explanation |
---|---|
ltr | Specifies that the element direction is from left to right. |
rtl | Specifies that the element direction is from rigth to left. |
auto | Specifies that the element direction must be determined based on the contents of the element. |
Set Direction
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<p dir="ltr">Click on the button.</p>
<button onclick="myFunction()">Toggle Button</button>
<p id="point"></p>
<script>
var elem = document.getElementsByTagName("p")[0];
function myFunction(){
if(elem.dir == "ltr")
elem.dir = "rtl";
else
elem.dir = "ltr";
}
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.