Possible Duplicate:
Change CSS of selected text using Javascript
Highlighting text spanning many elements
if (window.getSelection) {
userSelection = window.getSelection();
if (userSelection.getRangeAt) {
var range = userSelection.getRangeAt(0);
} else {
var range = document.createRange();
range.setStart(userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd(userSelection.focusNode, userSelection.focusOffset);
}
}
var newNode = document.createElement("span");
newNode.setAttribute('style', 'background-color:yellow');
range.surroundContents(newNode);
This is working for the case of text within the same tag like
Since span is inline block element which surrounds the selected text but I am not able to find any working solution for the case which includes other tags also in selected text like..
I am trying to do it for safari browser in ipad.
Do I need to parse the DOM element but I think it would consist of several cases.