admin管理员组文章数量:1241009
I am working rtl right to left direction. I want to know how to get dir value in alert using javascript.
Here is my html code
<html dir="rtl">
</html>
Here is my javascript code
alert(document.getElementsByTagName("html")[0]);
I am not getting the alert as dir ="rtl".
Based on the direction I have to do some condition checking. Instead of attribute is there any way please help me
Please help me how to get that tag name.
I am working rtl right to left direction. I want to know how to get dir value in alert using javascript.
Here is my html code
<html dir="rtl">
</html>
Here is my javascript code
alert(document.getElementsByTagName("html")[0]);
I am not getting the alert as dir ="rtl".
Based on the direction I have to do some condition checking. Instead of attribute is there any way please help me
Please help me how to get that tag name.
Share Improve this question edited Sep 25, 2024 at 11:03 Flimm 151k49 gold badges274 silver badges288 bronze badges asked Mar 3, 2015 at 12:47 Maha1419Maha1419 1911 gold badge2 silver badges11 bronze badges 1-
Have you tried
getAttibute
? Something like..document.getElementsByTagName("html")[0].getAttribute('dir')
– Rakesh_Kumar Commented Mar 3, 2015 at 12:49
3 Answers
Reset to default 9Thanks for the reply. Here is what i Did
if (document.dir == "rtl"){
function name()
}else{
function name1()
}
Regards Mahadevan
This snippet will get data directly from html element
document.getElementsByTagName("html")[0].getAttribute("dir");
you can get this more easily from the attributes of the document Document.dir
var direction;
(document.dir !=undefined)? direction =document.dir : direction =document.getElementsByTagName("html")[0].getAttribute("dir");
if (direction=="rtl") {
//do something
}
else {
//do something else
}
本文标签: How to get the dir attribute of the lthtmlgt element in JavaScript (RTL or LTR)Stack Overflow
版权声明:本文标题:How to get the dir attribute of the <html> element in JavaScript (RTL or LTR) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740077201a2223333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论