I’m trying to remove the tag inside this HTML but can’t seem to work out how:
<p>This is his: “<u><a href="https://secure.nm.com/"><strong>Fourth and Final Prediction</strong></a></u>.”</p>
I’ve tried this but it’s not working – where am I going wrong?
$("a:has(strong)").each(function() {
$(this).replaceWith($(this).children());
})
2
Answers
There are many ways to accomplish that.
If you want to remove all of the html you can replace the HTML with the text.
If you want to replace the HTML with everything in strong you can replace the HTML with the strong HTML:
You can use the jQuery
unwrap()
function:Demo:
The
.unwrap()
method removes the element’s parent and returns the unwrapped content.