Javascript Reference - HTML DOM Bdo Object








The Bdo class represents an HTML <bdo> element.

Bdo Object

The following code shows how to get a <bdo> element by using getElementById().


<!DOCTYPE html>
<html>
<body>
<bdo id="myBdo" dir="rtl">right-to-left</bdo>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--   w  w w  .java 2 s  .  c  o  m-->
    var x = document.getElementById("myBdo");
    if (x.dir === "rtl") {
        document.getElementById("demo").innerHTML = "right to left.";
    } else {
        document.getElementById("demo").innerHTML = "left to right.";
    }
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to create a <bdo> element by using the document.createElement() method:


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {<!--   w w w.  ja va2 s  .  c o  m-->
    var x = document.createElement("BDO");
    var t = document.createTextNode("right-to-left.");
    x.setAttribute("dir", "rtl");
    x.appendChild(t);
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows:





Bdo Object Properties

Property Description
dir Sets or gets the dir attribute of a <bdo> element. The dir attribute controls the text direction.

Standard Properties and Events

The Bdo object supports the standard properties and events.