How to set line breaking rules for non-CJK scripts in JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the wordbreak property in JavaScript to set line breaking rules for non-CJK scripts. The following are CJK scripts: C for Chinese, J for Japanese, K for Korean.

Example

You can try to run the following code to learn how to implement wordbreak property −

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            width: 150px;
            height: 120px;
            background-color: lightblue;
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <button onclick = "display()">Set</button>

      <div id = "box">
         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>

      <script>
         function display() {
            document.getElementById("box").style.wordBreak = "break-all";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 14:54:33
Advertisements