Search code examples
javascripthtmlcss

Direction rtl to all page


I have a long html page.
I want to change the direction of all text/tables to rtl.
How can i do that to all page instead of to change to any element the direction to rtl?
Thanks.


Solution

  • Using CSS:

    * {
        direction: rtl;
    }
    

    Using JavaScript:

    var children = document.children;
    var i;
    for (i = 0; i < children.length; i++) {
       children[i].style.direction = "rtl";
    }
    

    OR

    document.body.style.direction = "rtl";
    

    OR ( from evolutionxbox comment )

    document.body.setAttribute('dir', 'rtl')
    

    Using JQuery (even if you are not asking about):

    $("html").children().css("direction","rtl");
    

    Inline Coding:

    <body dir="rtl">
    

    OR

    <html dir="rtl">