Javascript Reference - HTML DOM Bdo dir Property








The dir property from <bdo> element sets or gets the value of the dir attribute.

The dir attribute controls the text direction inside a <bdo> element.

The dir attribute is required for <bdo> elements.

Browser Support

dir Yes Yes Yes Yes Yes

Syntax

Return the dir property:

var dir = bdoObject.dir;

Set the dir property:

bdoObject.dir='ltr|rtl';




Property Values

Value Description
ltr Set a left-to-right text direction
rtl Set a right-to-left text direction

Return Value

A string representing the text direction of the text, ltr or rtl.

Example 1

The following code shows how to change the text direction inside a <bdo> element to "right-to-left".


<!DOCTYPE html>
<html>
<body>
<bdo id="myBdo" dir="ltr">this is a test.</bdo>
<button onclick="myFunction()">test</button>
<!--   w w  w .  j a  va 2 s .  c o  m-->
<script>
function myFunction() {
    document.getElementById("myBdo").dir = "rtl";
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to get the text direction from a <bdo> element:


<!DOCTYPE html>
<html>
<body>
<bdo id="myBdo" dir="rtl">this is a test</bdo>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  www.  ja  v  a2  s  .  c o  m-->
    var x = document.getElementById("myBdo").dir;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows: