 <p>I can give you a part of the solution: how to select full words. My script is for textarea but you can make a few changes if you want to use div contenteditable instead.</p> <p><strong><a href="http://jsfiddle.net/pmrotule/ypv5y06j/2/" rel="nofollow">JSFIDDLE DEMO</a></strong></p> <pre><code>var lastSelectStart = 0; var lastSelectEnd = 0; saveSelection = function(){ lastSelectStart = document.getElementById("text").selectionStart; lastSelectEnd = document.getElementById("text").selectionEnd; } selectWords = function(){ var divEditable = document.getElementById("text"); html = divEditable.innerHTML; var start = lastSelectStart; var end = lastSelectEnd; var before = html.substring(0,start); var after = html.substring(end); var split = before.match(/[ .,;]/gi); var startIndex = before.lastIndexOf(split[split.length-1]) + 1; split = after.match(/[ .,;]/gi); var endIndex = after.indexOf(split[0]); endIndex = end + endIndex; divEditable.selectionStart = startIndex; divEditable.selectionEnd = endIndex; // startIndex is where you insert your stars and // (endIndex + number of stars added) is where you insert your stars again } </code></pre>