Hi,
I try to explain you my "problem". I would like to know when I select a part of text, if this text is “wrapped” by html tags, and in function delete them.
For example with this sentence :
The car is <strong>
green</strong>
, and the boat is black
If I select “green” and click on a button, I would like verify if green is wrapped by <strong>
(for that it’s ok), and in function delete <strong>
tags without delete containing “green”.
I have tried to do it, but when I remove child and recreate one, my new node is empty and if I try to put directly text in document.createTextNode
, my new node appears but the <strong>
tags stay.
// 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’m not a DOM manipulation specialist. Could you help me to solve this?
Thanks very much for your precious help.