How to set how the last line of a block or a line right before a forced line break is aligned when text-align is "justify" with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the textAlignLast property in JavaScript to set the last line to right. Set it to right and allow the right alignment.

Example

You can try to run the following code to return how the last line of a block or a line right before a forced line break is aligned when text-align is "justify" with JavaScript −

<!DOCTYPE html>
<html>
   <head>
      <style>
         #myDIV {
            text-align: justify;
         }
      </style>
   </head>

   <body>
      <div id = "myText">
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
         This is demo text. This is demo text. This is demo text. This is demo text.
      </div>
      <button onclick = "display()"> Set Alignment </button>
      <script>
         function display() {
            document.getElementById("myText").style.textAlignLast = "right";
            ;
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 07:33:45
Advertisements