How to set the horizontal alignment of text with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the textAlign property in JavaScript and set it to right for aligning it horizontally. You can try to run the following code to return the horizontal alignment of text with JavaScript −

Example

<!DOCTYPE html>
<html>
   <body>
      <p id = "myText">This is demo text</p>
      <button onclick = "display()">Set Horizontal Alignment</button>
      <script>
         function display() {
            document.getElementById("myText").style.textAlign = "right";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 07:28:35
Advertisements