How to set the text direction with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

To set the text direction, use the direction property with JavaScript. Set rtl for right-to-left or ltr for left-to-right text direction.

Example

You can try to run the following code to set the text direction with JavaScript −

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <h1 id="myID">Heading 1</h1>
      <p>Click below to set the direction of heading to Left-to-right</p>
      <button type="button" onclick="display()">Click to change the direction</button>
      <script>
         function display() {
            document.getElementById("myID").style.direction = "rtl";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 12:08:20
Advertisements