javascript - Highlight selected word -
i need implement both highlight , un-highlight selected text in textarea. please me implement one. tried following code highlight , un-highlight
$('.highlight').click(function(){ var selection= window.getselection().getrangeat(0); var selectedtext = selection.extractcontents(); var span= document.createelement("span"); span.style.backgroundcolor = "yellow"; span.appendchild(selectedtext); selection.insertnode(span); }); $('.remove_highlight').click(function(){ var selection= window.getselection().getrangeat(0); var selectedtext = selection.extractcontents(); var span= document.createelement("span"); span.style.backgroundcolor = "white"; span.appendchild(selectedtext); selection.insertnode(span); });
here, .highlight , .remove_highlight separate buttons, in advance
Comments
Post a Comment