- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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?
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>
Advertisements