[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • Last Modified:

Javascript: How can i apply font size in pixels?

I'm creating a text editor and making use of the contentEditable property on a <div>. My function to specify the font currently using:

document.execCommand('fontSize', false, fSize)

where fSize is a number from 1 to 7, corresponding to the allowable values for <font size="XXX">.

However, this does not support specifying the font size in pixels. Have seen various posts about this on the internet, but no solution has been posted, just one saying that it must be implemented using DOM+ functions.

I came up with the attached code, which works if a user has selected some text, but this depends on some text being selected.

Any ideas?
selection=document.selection.createRange();
selection.pasteHTML("<span style='font-size: 24px;'>" + selection.htmlText + "</span>");

Open in new window

0
paddycobbett
Asked:
paddycobbett
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
0
 
KelevraCommented:
Hi,

Have you considered using JQuery in your work?

http://docs.jquery.com/CSS/css#namevalue
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now