Remove a HTML tag but keep the innerHtml
jquery
Solution
$('b').contents().unwrap();
This selects all `<b>` elements, then uses `.contents()` to target the text content of the `<b>`, then `.unwrap()` to remove its parent `<b>` element.
For the greatest performance, always go native:
var b = document.getElementsByTagName('b');
while(b.length) {
var parent = b[ 0 ].parentNode;
while( b[ 0 ].firstChild ) {
parent.insertBefore( b[ 0 ].firstChild, b[ 0 ] );
}
parent.removeChild( b[ 0 ] );
}
This will be much faster than any jQuery solution provided here.
Problem
I have some simple HTML which I need to strip simple formatting. ``` A nice house was found in <b>Toronto</b>. ``` I need to remove the bold, but leave the sentence intact. How is this possible in jQuery?