(^476) ❘ CHAPTER 22 CREATING A SIMPLE WYSIWYG EDITOR
}
function setSelectionRange(range)
{
if (range && window.getSelection)
{
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}This code results in the document shown in Figure 22-3.
FIGURE 22-3
The markup now includes a button for creating a selection within the editable element:
<button id='btnCreateSelection'>Create Selection</button>You added a click event handler for this button to the JavaScript code:
$('button#btnCreateSelection').click(
function()
{
var container = document.getElementById('container');