I store in a variable my range that the user has selected.
var sel, range, off, tags;
sel = window.getSelection();
if (sel.rangeCount) {
range = sel.getRangeAt(0);
var off = sel.anchorOffset;
}
else if (document.selection && document.selection.createRange) {
range = document.selection.createRange();
var off = document.selection.anchorOffset;
}
return range;
html
<div ng-mouseup="mouseUpEvent(e)" ng-keyup="keyUpEvent()" contenteditable data-element="textBlock" id="markdown-body">
Chicken ipsum dolor sit amet, consectetur adipiscing elivolutpat volutpat. Nunc imperdiet urna et orci mattis,
pellentesque posuere enim pellentesque. Aenean id orci et nunc venenatis vestibulum et et ligula. Morbi mollis ornare purus
non blandit.<b> Phasellus egestas</b>, ipsum <i>sit amet finibus </i>pellentesque, <span style="color: red;">tellus urna
lobortis tellus, id tincidunt </span>Piza house byys nget lectus. Proin pulvinar enim non mi vestibulum interdum.
Sed nisl enim, sagittis non vestibulum eget, congue pellentesque ipsum. Nullam nec interdum elit
</div>
I have located my anchorNode and my focusNode. So i have selected my node that nodeName "B". Stand for Bold.
If I do element.nodeName my output will be "B".
if I output my element I get <b> Phasellus egestas</b>
I also got a selected range, and I have selected "asellus eges"
I would like to remove <b>
tags. and add tags to the select range.
If I take the innerHTML of the element and replace it, than I mess up by select range.
I have seen that people suggest doing finding the parent and than selecting the childNode and removing and doing something like:
element[index].parentNode.removeChild(element[index]);
But that will cause an issue if my Parent has two child nodes with the same nodeName.
I already got the element to select the specific Node , how do I keep the innerConnet & HTML markup but delete the b tags?