CSharpBeginner
CSharpBeginner

Reputation: 611

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.

Upvotes: 10

Views: 19975

Answers (5)

Gil Lupu
Gil Lupu

Reputation: 41

You can use jQuery.

$('body').children().css('direction','rtl');

Or use pure Javascript:

document.getElementsByTagName('Body')[0].style.direction = "rtl"

Upvotes: 4

ITChristian
ITChristian

Reputation: 11271

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">

Upvotes: 19

rejo
rejo

Reputation: 3350

Javascript

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

HTML

<body dir="rtl">

Upvotes: 1

Dipak Prajapati
Dipak Prajapati

Reputation: 528

The direction property in CSS sets the direction of of content flow within a block-level element. This applies to text, inline, and inline-block elements. It also sets the default alignment of text and the direction that table cells flow within a table row.you can use

body {
  direction: rtl;  /* Right to Left */
}

or There is an HTML attribute for setting the direction as well

<body dir="rtl">

It is recommended you use the HTML attribute, as that will work even if CSS fails or doesn't affect the page for any reason.

Upvotes: 5

webdevanuj
webdevanuj

Reputation: 675

using css:

html * {
  direction: rtl;
}

using jQuery:

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

Upvotes: 0

Related Questions