In my page, user select a text, once they select i am passing the selected object to function. In the function i would like to get the appropriate text note using jquery.. how to get that?
here is my function :
var manipulator = function (coreObject) {
console.log(coreObject);//i would like find the text node using this object and like to wrap in to a element say 'span'...
}
function highlight() {
var range, sel;
var span = document.createElement("span");
span.style.fontWeight = "bold";
span.style.color = "green";
// IE case
if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
manipulator(range)
} else if (window.getSelection) {
// Non-IE
sel = window.getSelection();
manipulator(sel)
}
}
$("#addText").on('click', function(event) {
event.preventDefault();
highlight();
});
I am looking for all browser friendly approach.