You can prevent line breaks after short words by replacing any space after those words with a non-breaking space. This displays like a normal space, but doesn't allow the text to be wrapped at this point. E.g.
mydiv.innerHTML = mytext.replace(/\b(\w{1,3})\s+/g, '$1 ');
The {1,3}
specifies words of one to three alphanumeric characters in length. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions for details. You way wish to adjust the regular expression for your own requirements.
I don't think the effect is especially visually pleasing. Browsers don't have very sophisticated word-wrapping algorithms.