i search for "how to replace selected text in div", and i found but it dosent work for html tags, how can i replace text and do a bold text for example? this is the code that i found:
function wrap(tag) {
var sel, range;
if (window.getSelection) {
sel = window.getSelection();
if (sel.rangeCount) {
range = sel.getRangeAt(0);
selectedText = range.toString();
range.deleteContents();
range.insertNode(document.createTextNode('<jhjhgjhjhgj>' + selectedText + '</' + tag + '>'));
}
}
else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
selectedText = document.selection.createRange().text + "";
range.text = '<' + tag + '>' + selectedText + '</' + tag + '>';
}
}