• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to change font properties, of subsection of page.

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use css classes


you have your div


and you have your javascript


Eric
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67748
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic