- 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 allow long and unbreakable words to be broken and wrap to the next line in JavaScript?
Use the wordWrap property in JavaScript to allow long words to be broken and wrap to the next line.
Example
You can try to run the following to learn how to work with wordWrap property −
<!DOCTYPE html> <html> <head> <style> #box { width: 150px; height: 150px; background-color: lightblue; border: 1px solid black; } </style> </head> <body> <button onclick = "display()">Set</button> <div id = "box"> ThisisDemoText.ThisisDemoText.ThisisDemoText.ThisisDemoText.Thisis DemoText.ThisisDemoText. </div> <script> function display() { document.getElementById("box").style.wordWrap = "break-word"; } </script> </body> </html>
Advertisements