I’ve got a string which at times contains css font sizes.
For example:
str = '<span style="font-size: 200px;white-space:nowrap;">Text</span>
<br><span style="color:#555555;font-size:10px;">Some otherText</span>';
I need to change all the font sizes by multiplying them all by a set ratio of for example 1.5
var ratio = 1.5;
Search and replace is not my strong suit. How do I search the string for all font sizes and then do the math on each number?
So that the above string with this ratio will become:
str = '<span style="font-size: 300px;white-space:nowrap;">Text</span>
<br><span style="color:#555555;font-size:15px;">Some otherText</span>';
Assuming that have that as a string and there is not a better way (if this came from
innerHTMLor so, you’re doin’ it wrong), then…jsFiddle.
If your browser doesn’t suck…
If any of the declarations were not in the
styleattribute, you could usegetComputedStyle().I didn’t use a real
documentFragment, because it doesn’t support theinnerHTMLproperty.