This returns an empty string when I try to determine the default text direction...
alert(document.getElementById('example').dir);
I would like to determine if the default text direction is ltr or rtl.
This returns an empty string when I try to determine the default text direction...
alert(document.getElementById('example').dir);
I would like to determine if the default text direction is ltr or rtl.
ltr/rtl is defined with the css "direction" property. It can also be defined using the "dir" attribute on the element in the DOM.
If you're checking for the attribute value, use the getAttribute method:
document.getElementById('example').getAttribute('dir');
Also, check the style of the element. It defaults to ltr so if undefined, should return as an empty string. Otherwise it should say "rtl"
document.getElementById('example').style.direction;
I'd use
var elm = document.getElementById('example') || document.body;
return window.getComputedStyle(elm).direction;
if it is blank that means it isn't specified in your element's dir
attribute.