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 8982779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:39:48+00:00 2026-06-15T20:39:48+00:00

Is there a way using javascript and HTML to change the color of a

  • 0

Is there a way using javascript and HTML to change the color of a span? For example:

<span onLoad="document.getElementById('test').style.color = 'red';" id="test">test</span>

But that doesn’t seem to work.

Quick update: This is just a precursor to the actual problem that I’m trying to solve. Basically I’m inside a CMS that only allows for in place HTML editing. That means that I don’t have access to the head to add custom javascript functions etc. What I’m trying to do is make an inline function that takes the date specified (in a span for example) and then colorizes it based on some in-line js logic.

  • 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-06-15T20:39:49+00:00Added an answer on June 15, 2026 at 8:39 pm

    Spans do not have an “onload” event. If you want to run that when the page loads, add a script block on the <head> with the following code:

    window.onload = function() {
        document.getElementById('test').style.color = 'red';
    }
    

    Considering your clarification about not having access to the header: you can add a <script> block anywhere below the elements you’re targeting, and it works. If possible, add a single script block before </body> (or as far down as possible). Another possibility is just adding a class from the CMS editor, and define that class on an external CSS file. Yet another possibility are inline CSS styles, as suggested on defau1t’s answer.

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

Sidebar

Related Questions

Is there a way to parse html content using javascript? I have a requirement
Is there a way to access the page HTML source code using javascript? I
Is there any way to completely process a form using only javascript & html
is there any way to change arabic font in UIWebView from html file using
When debugging HTML is there a way to listen for div width change using
Is there a way to take a screenshot using PIL of an specified HTML/Javascript
I'm trying to figure out if there is a way (using JavaScript, or jQuery
Is there any way to cut an image into smaller pieces using JavaScript? Like,
Is there a way to get the a users screen size/resolutions using javascript? I
Is there a reliable way to access the client machine's clipboard using Javascript? I

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.