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

  • SEARCH
  • Home
  • 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

I have this code as an example: <html> <head> <script type=text/javascript src=https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js></script> <script type=text/javascript>
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the
For example… This PHP code <?php echo '<html>'; echo '<body>'; echo '<h1>Header One</h1>'; echo
I all, I just follow this great example: http://qt-project.org/doc/qt-4.8/tools-customcompleter.html I copy the code exactly
I'm working with a Google Maps example code , this : http://www.wolfpil.de/v3/drag-from-outside.html which has
I used below code for customize the file input type, <form class=example action=#> <!--<input
I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
in this example http://sorgalla.com/projects/jcarousel/examples/static_controls.html i need an active state on li so it should
Please see this example: if (strlen($_SESSION['userDetails']['THISNAME']) == 0) { $_SESSION['userDetails'][''.$THISNAME.'Error'] = autofocus; include $docRoot/html/forms/reg/user_info.html.php;

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.