<p>
lorem ipsum lorem ipsums <font style="background-color:yellow">ipsum</font> ipsume lorem
</p>
how to replace the <font> tag with <abbr> so the out put will be like this.
<p>
lorem ipsum lorem ipsums <abbr style="background-color:yellow">ipsum</abbr> ipsume lorem
</p>
Finds all font tags within any p, and replaces it with an abbr with the style attribute and text copied over.
$("p font").each(function() {
var font = $(this);
var abbr = $("<abbr>", {
style: font.attr("style"),
text: font.text()
});
font.replaceWith(abbr);
});
This will replace all <font and </font with <abbr and </abbr.
var p = document.getElementsByTagName("p")[0]; // assume this is the first P in the document
var p.innerHTML = p.innerHTML.replace(/(<|<\/)font/g, "$1abbr")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With