Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
173
rated 0 times [  176] [ 3]  / answers: 1 / hits: 33342  / 13 Years ago, tue, may 3, 2011, 12:00:00

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.


More From » editor

 Answers
28

It's a limitation of the FontSize command. There are various options I can think of:




  • You could use a CSS class instead and use the CSS class applier module of my Rangy library;

  • You could use a hacky method, such as calling 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.


[#92433] Sunday, May 1, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tajo

Total Points: 415
Total Questions: 124
Total Answers: 103

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;