Solved

Javascript: How can i apply font size in pixels?

Posted on 2009-07-07
2
430 Views
Last Modified: 2012-05-07
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
Comment
Question by:paddycobbett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24795435
0
 
LVL 3

Accepted Solution

by:
Kelevra earned 500 total points
ID: 24807280
Hi,

Have you considered using JQuery in your work?

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question