How can I change font size to 30px (for example) using document.execCommand
?
This:
document.execCommand("fontSize", false, "30px");
doesn't work, because in 3rd argument of the function execCommand, it only allows me to input a value between and including 1 to 7.
It's a limitation of the FontSize
command. There are various options I can think of:
document.execCommand("fontSize", false, "7");
and then finding the elements the command has created and changing them as required. See example: http://jsfiddle.net/S3ctN/. This obviously depends on there being no other <font>
elements with size 7 in the document and it also relies on the browser using <font>
elements for font size, which it seems they all do.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