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.
dir |
Yes | Yes | Yes | Yes | Yes |
Return the dir property:
var dir = bdoObject.dir;
Set the dir property:
bdoObject.dir='ltr|rtl';
Value | Description |
---|---|
ltr | Set a left-to-right text direction |
rtl | Set a right-to-left text direction |
A string representing the text direction of the text, ltr or rtl.
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:
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: