Solved

Javascript: How can i apply font size in pixels?

Posted on 2009-07-07
2
440 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

752 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