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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:56:50+00:00 2026-06-13T16:56:50+00:00

I want to target this: <h3 id=’month’>Oct</h3> I did this: var changeColor = function

  • 0

I want to target this:

<h3 id='month'>Oct</h3>

I did this:

    var changeColor = function () {
        var monName = new Array ('Jan' ... 'Dec'); //ellipsis to make code short
        var now = new Date();

        if(monName == monName[now.getMonth()]) {
           switch(monName) {
                case 'Jan':
                   document.getElementById('month').style.backgroundColor = '#ff3300';
                   break;
                   .
                   .
                   .
                   .
                case 'Dec':
                   document.getElementById('month').style.backgroundColor = '#c2dd8a';
                   break;
                default:
                   alert('Error');

                }     
        }
};

I called the function in the html body element (external js file between script tags properly sourced already):

<script type='text/javascript' src='time.js'></script>
<body onload='changeColor();'>

It didn’t seem to work. I’m suspecting there is an error with how I target the h3 element. My overall idea is to change the background color as the month changes for the targeted element. Any help is greatly appreciated. Thanks!

  • 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-13T16:56:51+00:00Added an answer on June 13, 2026 at 4:56 pm

    Try to change your if statement to:

    if(document.getElementById('month').innerHTML == monName[now.getMonth()])
    

    Also, your switch statement should be:

    switch(monName[now.getMonth()])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not sure how to target the element I want in this case: var
I can check for iPhone with this code: (navigator.userAgent.match(/iPhone/i)) But I want to target
I want to implement DropTargetListener with a JTable as a target. This is roughly
I have this code: var originalBorder = container.css("border"); container.hover(function(event) { event.stopPropagation(); $(this).css("border", "1px solid
I have makefile with modules target. Without changing this target, I want to add
I want to target this input and change it dynamically with jQuery: <select id=sub_cat
Is this possible? I want to target iOS 4.0 and the iPhone 4 device
How does this data.target == this work? jquery example .mouseup(function(data, handler) { if(data.target ==
So I have this makefile and I want the target all just to invoke
If I have this: <span data-helo=1>something</span> <span data-helo=2>something different</span> and I want to target

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.