Any idea how to find and replace the HTML font-size in style attribute?
eg. <span style="font-size:12px">hello world</span>
I would like to remove all font-size using javascript.
Thank you
Any idea how to find and replace the HTML font-size in style attribute?
eg. <span style="font-size:12px">hello world</span>
I would like to remove all font-size using javascript.
Thank you
OH GOD NO NOT REGULAR EXPRESSIONS AAAAAAHHHHHH ;-) You should do this using the DOM manipulation methods of Javascript - that's what they're there for.
var theSpan = ...;
theSpan.style.removeProperty("font-size");
Here's one reference.
$("span").each( function() {
$(this).css("font-size", "");
});
You can loop through the desired elements using jquery.
Here's an example of a Javascript function to find all spans and replace their font size.
function changeFontSize(newSize) {
var spans = document.getElementsByTagName('span');
for(var i=0;i<spans.length;i++)
{
spans[i].style.fontSize=newSize ;
}
}
The argument newSize is a string. If you set it to "50px", all spans will have a 50px font size. If you set it to "", it will have the same effect as removing the fontsize.