You'll need to create a function that has all the letters you know are RTL and check when loading. To display RTL you need the CSS attributes, direction
, text-align
, and unicode-bidi
.
Demo:
Script
function checkRtl( character ) {
var RTL = ['?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?','?'];
return RTL.indexOf( character ) > -1;
};
var divs = document.getElementsByTagName( 'div' );
for ( var index = 0; index < divs.length; index++ ) {
if( checkRtl( divs[index].textContent[0] ) ) {
divs[index].className = 'rtl';
} else {
divs[index].className = 'ltr';
};
};
CSS
.rtl {
direction: rtl;
text-align: right;
unicode-bidi: bidi-override;
}
.ltr {
direction: ltr;
text-align: left;
unicode-bidi: bidi-override;
}
HTML
<div>hello</div>
<div>?</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…