How to detect text direction of element using Javascript?

前端 未结 4 776
渐次进展
渐次进展 2021-02-06 18:19

What\'s the best way to detect the text direction of an html element using Javascript? I would expect to get either \"rtl\" or \"ltr\".

4条回答
  •  无人共我
    2021-02-06 18:36

    Try this

    document.defaultView.getComputedStyle(document.getElementById('baz'),null)['direction'];
    

    OR

    style = document.defaultView.getComputedStyle(document.firstChild,null);
    console.log(style.direction);
    

提交回复
热议问题