File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How to change font properties, of subsection of page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to change font properties, of subsection of page. " Watch "How to change font properties, of subsection of page. " New topic
Author

How to change font properties, of subsection of page.

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Is there a way to change the font color and size of a text with a button click? I do not want to change the font size and color of the entire page just a section of it.

For example a sentence in a paragraph will change to red, while the rest stay black, or the font size of a word on a paragraph changes size, but the rest stay the same on a button click.

The problem I have is that the examples I read like:

document.bgColor = '#FFFFFF';
document.fgColor='#FF0000';

Affects the whole page, I cannot figure out how to change a small section of the page. Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Use css classes


you have your div


and you have your javascript


Eric
Malith Yapa
Ranch Hand

Joined: Jan 17, 2007
Posts: 45
I think there is a more convenient way.

Just get the appropiate paragraph element using the

method and change it's style objects properties.



this would actually change the paragraphs color to red on the run..

After that all you have to do is create a function with the above code and call it from the onklick event. Like this.


the " | " are for te greater than and smaller than signs. Javaranch doesn't support them
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61601
    
  67

Originally posted by Malith Yapa:
I think there is a more convenient way.


That is a much more inconvenient way. Using that approiach each and every element in the section would need to be iterated over in order to change the color.

Much better to make one class name change and affect the entire DOM sub-tree.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
Thanks guys, your sample code works great! I kinda knew I would have to use div but, didn't know how to change its class name, until now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change font properties, of subsection of page.