Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7588725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:59:35+00:00 2026-05-30T19:59:35+00:00

For example, this is my html code: ​<p style=color:blue>​I’m Blue</p> <p id=p_red>I’m Red​</p> <p>​I’m

  • 0

For example, this is my html code:

​<p style="color:blue">​I'm Blue</p>
<p id="p_red">I'm Red​</p>
<p>​I'm default, black</p>
<input type="button" id="btn" value="Set color" />  

css:

​#p_red{
    color: red;
}​  

I’d like to turn the page’s font color to green when the button is clicked:

document.getElementById("btn").onclick = function(){
    document.body.style.color = "green";
}​;​  

But it seems that only the default one(the black one) changed, the blue and red one doesn’t work…
How could do this?

Fiddle here: http://jsfiddle.net/M5AQ4/

​

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:59:36+00:00Added an answer on May 30, 2026 at 7:59 pm

    Rather than setting the colour directly, assign a style to the body as follows:

    document.body.className += " green";
    

    Where the “green” style is in your stylesheet as follows:

    #p_red{
        color: red;
    }
    body.green, .green p {
        color: green !important;
    }
    

    Demo: http://jsfiddle.net/M5AQ4/5/

    The body.green, .green p selector in the stylesheet will apply the specified colour to the body only when it has the “green” class, and to any p elements that are descendents of an element that has the “green” class – the !important flag means it will override other styles that might otherwise have taken precendence under normal cascade rules. You can change the second selector to .green * to apply it to all element types that are descendts of “green”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example this code var html = <p>This text is <a href=#> good</a></p>; var
example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the
Hey! I was looking at this code at http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html I noticed that in some
i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what
I'm following this example: http://www.codinghorror.com/blog/2005/12/getting-started-with-indexing-service.html However, the conversion to dataset shows empty columns for
Take a look at this example: http://www.extjs.com/deploy/dev/examples/multiselect/multiselect-demo.html On it, there are components rendered against
Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %>
Let's say this page www.example.com/mypage returns some html that I want to parse in
So I found this: http://tiles.apache.org/framework/tutorial/advanced/nesting-extending.html Here is the example: <definition name=myapp.homepage template=/layouts/classic.jsp> <put-attribute name=title
I'm looking for a code library that converts ANSI escape sequences into HTML color,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.