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
}