I am trying to explain my “problem” to you. I would like to know when I select a part of the text, if this text is “wrapped” with html tags, and in the function it will be deleted.
For example, with this sentence:
The car is <strong> green </strong> and the boat is black
If I select “green” and press the button, I would like to check whether it is completed in “green” using <strong> (for this it is normal) and in the function tag <strong> tags without deletion containing “green”.
I tried to do this, but when I delete the child and recreate it, my new node is empty, and if I try to put the text directly in document.createTextNode , a new node will appear, but the <strong> tags remain.
// Bouton CLICK $('input[type=button].btn_transform').click(function(){ var selObj = window.getSelection(); var parent=selObj.anchorNode.parentNode; if (parent.nodeName=='STRONG'){ parent.removeChild(selObj.anchorNode); var theText = document.createTextNode(selObj); parent.appendChild(theText); } });
I am not a specialist in manipulating the DOM. Could you help me solve this problem?
Thanks so much for your precious help.
source share