Reputation: 23
I want to make a bold text non-bold using Greasemonkey. I have only found ways to remove the tag along with its text, but not a way to simply remove the tag itself.
So how do I make
<b>
some text
</b>
just
some text
?
Upvotes: 2
Views: 1968
Reputation: 8783
Assuming you've only one TextNode inside each B tag.
b.parentNode.replaceChild(b.firstChild, b);
Example : http://jsfiddle.net/DGTh5/
Upvotes: 2
Reputation: 1075219
Assuming you're dealing with elements, not a string:
function unwrapChildren(element) {
var parent, node, nextNode;
parent = element.parentNode;
for (node = element.firstChild; node; node = nextNode) {
nextNode = node.nextSibling;
parent.insertBefore(node, element);
}
parent.removeChild(element);
}
Then call unwrapChildren
with the b
element. The above will move all of its child nodes (there's probably only one, a text node) into the b
element's parent node where the b
element is, and then remove the b
element.
Upvotes: 1