javascriptright-to-left

How to detect current web page or element direction (rtl/ltr) or any other attribute in javascript?


How can i read any attribute that currently effects an element that is not necessarily style? one such attribute would be "dir".


Solution

  • Recently I had similar problem, you can get element's property with window.getComputedStyle and element.currentStyle methods:

        var elem = document.getElementById('test');
        if (window.getComputedStyle) { // all browsers
            cs = window.getComputedStyle(elem, null).getPropertyValue('direction');
        } else {
            cs = elem.currentStyle.direction; // IE5-8
        }
        alert(cs);
    

    jsfiddle ; compatibility info