Allow long words to be able to break and wrap onto the next line:
document.getElementById("myDIV").style.wordWrap = "break-word";
Click the button to change the let the DIV element wrap words:
<!DOCTYPE html> <html> <head> <style> #myDIV {/*from www . j a va2 s . c om*/ width: 150px; height: 100px; background-color: lightblue; border: 1px solid black; } </style> </head> <body> <div id="myDIV">testtesttesttesttesttesttesttesttesttesttesttesttesttest</div> <button onclick="myFunction()">Test</button> <script> function myFunction() { document.getElementById("myDIV").style.wordWrap = "break-word"; } </script> </body> </html>
The wordWrap property allows long words to be able to be broken and wrap onto the next line.
Property Values
Value | Description |
---|---|
normal | Default . Break words only at allowed break points |
break-word | Allows unbreakable words to be broken |
initial | Sets this property to its default value. |
inherit | Inherits this property from its parent element. |
The wordWrap property returns a String representing the word-wrap property of an element.