Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Test Page</title>
<style>
  body {
    font-family: sans-serif;
  }
</style>
</head>
<body>
  <p></p>  
</body>
</html>
 
  function splitString(str, index) {
    var delim = /\s|[,\.]/; // Put any other character you consider
                            // a non-word char in the brackets
    var ch;
    var i,n;
    
    for (i = index;
         i <= 40 && !delim.test(str.charAt(i));
         --i) {
      // No body
    }
    if (i < 0) {
      // No break before, split word in middle
      n = index;
    }else n = i;
    if(n<str.length) return str.substring(0,n)+'...';
    else return str;
  }
  var str, splitPoint;
  
  str = "Ich bin ein Blindtext oder der nichts kann";  splitPoint = splitString(str, 25);
  display(splitPoint);
  function display(msg) {
     
    var aaa = document.GetElementsByTagName("<p>").innerHTML = (msg);
  }
Output 300px

This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account

Dismiss x
public
Bin info
anonymouspro
0viewers