0

i'm trying to edit html using javascript statement that includes numeral variable concatenated with arabic string this is an example for my code:

<html>
<body>
<p id="example"></p>
<script>
var x = "متر ";
var y = 5;
document.getElementById("demo").innerHTML = y + x;
</script>

</body>
</html> 

the result that I want is the var y before the var x so it would show as rtl but im always getting it as ltr

i really hope that i explained the issue properly any help?

  • this is because arabic is written from the right to the left?^^ – messerbill Feb 27 '18 at 10:57
  • use `dir="rtl"` in your `

    ` tag and change `y+x` to `x+y` moreover, your `id="example"` so `getElementById("demo")` is wrong.

    – abdul qayyum Feb 27 '18 at 11:01
  • 4
    Possible duplicate of [use text-align smartly (if english dir=ltr if arabic dir=rtl)](https://stackoverflow.com/questions/11787351/use-text-align-smartly-if-english-dir-ltr-if-arabic-dir-rtl) – abdul qayyum Feb 27 '18 at 11:02
  • There are many answers already available on SO. So please search before you post a duplicate. – abdul qayyum Feb 27 '18 at 11:02

1 Answers1

0

This is the answer that was required but everybody answered only part one of many.

  • Step 1 - You cannot have the multilingual characters in unicode document.. convert the document to UTF-8 document

advanced editors don't make it simple for you... go low level...
use notepad to save the document as meName.html & change the encoding
type to UTF-8

  • Step 2 - Mention in your html page that you are going to use such characters by

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    
  • Step 3 - When you put in some characters make sure your container tags have the following 2 properties set

    dir='rtl'
    lang='ar'
    
  • Step 4 - Get the characters from some specific tool\editor or online editor like i did with Arabic-Keyboard.org

example

<div dir="rtl" lang="ar" style="color:#e0e0e0;font-size:20px;">رَبٍّ زِدْنٍي عِلمًا</div>

NOTE: font type, font family, font face setting will have no effect on special characters

аlex
  • 5,426
  • 1
  • 29
  • 38