I want to select an image and a add a class name to the selection. using window.getSelection.
function addClassName() {
var sel = window.getSelection();
//what goes here???
}
<input type='button' onclick='addClassName();' value='addClassName'/>
To add class to selection, you need to wrap it with
<span>other wise it will not work. Here’s the solution.This should guide you in the proper direction. Modify it as you see fit.
Check working example at http://jsfiddle.net/wP8w9/2/