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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:00:33+00:00 2026-05-30T08:00:33+00:00

I am trying to make an ‘opening hours’ table that highlights the current day

  • 0

I am trying to make an ‘opening hours’ table that highlights the current day for the user.

HTML:

                    <div id="Monday"> <h2> Mon</h2><h3>8am-9pm</h3></div>
                    <div id="Tuesday"> <h2> Tue</h2><h3>8am-9pm</h3></div>
                    <div id="Wednesday"> <h2> Wed</h2><h3>8am-9pm</h3></div>
                    <div id="Thursday"> <h2> Thu</h2><h3>8am-9pm</h3></div>
                    <div id="Friday"> <h2> Fri</h2><h3>8am-9pm</h3></div>
                    <div id="Saturday"> <h2> Sat</h2><h3>8am-9pm</h3></div>
                    <div id="Sunday"> <h2> Sun</h2><h3>8am-9pm</h3></div>

jQuery/Javascript/Idon’tevenknowanymore:

var d=newDate();
var day=d.getDay();

if (day == 1)
    {
        document.getElementById('Monday').style.color='#DB35B0'
    }
else if (day == 2)
    {
        document.getElementById('Tuesday').style.color='#DB35B0'
    }
else if (day == 3)
    {
        document.getElementById('Wednesday').style.color='#DB35B0'
    }
else if (day == 4)
    {
        document.getElementById('Thursday').style.color='#DB35B0'
    }
else if (day == 5)
    {
        document.getElementById('Friday').style.color='#DB35B0'
    }
else if (day == 6)
    {
        document.getElementById('Saturday').style.color='#DB35B0'
    }
else if (day == 0)
    {
        document.getElementById('Sunday').style.color='#DB35B0'
    }

The trouble is that if I was going to change the color in the css I would use:

      #Friday h3 {color:#DB35B0;}

which doesn’t seem to work in the Javascript like this:

      else if (day == 5)
    {
        document.getElementById('Friday h3').style.color='#DB35B0'
    }

I also tried:

      else if (day == 5)
    {
        document.getElementById('Friday').children.style.color='#DB35B0'
    }

But that did nothing.

So what do I do?

Is it possible to target the children of the divs and change their color?

  • 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-30T08:00:34+00:00Added an answer on May 30, 2026 at 8:00 am

    Yes, there are various methods to retrieve descendant elements (such as getElementsByTagName), but getElementById does not accept a CSS selector. The reason why [...].children.style does not work is that .children returns a NodeList, i.e. a collection of nodes. You’d have to iterate over it or access it with the index of the node you want.

    I suggest a different, easier approach:

    Create a CSS rule for the color, using a class:

    .today h3 {
       color: #DB35B0;
    }
    

    Add that class to the current day:

    var days = ['Sunday', 'Monday', ..., 'Saturday'],
        now = new Date(),
        today = now.getDay();
    
    document.getElementById(days[today]).className += ' today';
    

    This is less code and you can make changes to the style more easily.

    Edit: I just saw that you tagged the question with jQuery. In that case, you can replace the last line with:

    $('#' + today).addClass('today');
    

    In contrast to DOM interface methods such as getElementById or getElementsByTagName, jQuery uses CSS selectors to get references to elements. You should have a look at the documentation if you intend to use it.

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

Sidebar

Related Questions

Trying to make kinda WISYWIG editor that creates a div with some inner elements.
Trying to make a make generic select control that I can dynamically add elements
Trying to make a custom :confirm message for a rails form that returns data
Im trying to make a function that will return an element of type point:
Trying to make td elements clickable. Here's my HTML: <td id=A3 class= open-square><a href=/gameplay/A3></a></td>
Trying to make simple jQuery function to create a scrollToTop button that fades in
Trying to make infoWindows a little less uglier I found out that the infoWindows
im trying to make an image gallery. the container class that adds the thumbnail
trying to make one horizontal box.. inside that update limits. if u see the
Im trying to make an app that converts distance/area/volume using spinners as a unit

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.