- 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 the horizontal alignment of text with JavaScript?
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>
Advertisements