If my slected text is wrapped in bold or iltalic or pre tag and then if i click on the revert button it should remove the tags around the selected text. But for some reason will not with my code.
Question when I select/highlight some text and then click my revert button how to make it remove the tags that are around that selected/highlighted text.
Codepen Live Demo
Codepen Full View Live Demo
$(document).ready(function() {
$("button[id='revert']").on('click', function() {
var text, sel, range;
if (window.getSelection) {
text = window.getSelection().toString();
sel = window.getSelection();
if (sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(range.createContextualFragment(text));
}
} else if (document.selection && document.selection.createRange) {
text = document.selection.createRange().text;
range = document.selection.createRange();
range.innerHTML = text;
}
$('#code_view').trigger('click');
});
});