Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery/javascript change color of text depending on day
    text
    copied!<p>I am trying to make an 'opening hours' table that highlights the current day for the user.</p> <p>HTML:</p> <pre><code> &lt;div id="Monday"&gt; &lt;h2&gt; Mon&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Tuesday"&gt; &lt;h2&gt; Tue&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Wednesday"&gt; &lt;h2&gt; Wed&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Thursday"&gt; &lt;h2&gt; Thu&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Friday"&gt; &lt;h2&gt; Fri&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Saturday"&gt; &lt;h2&gt; Sat&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; &lt;div id="Sunday"&gt; &lt;h2&gt; Sun&lt;/h2&gt;&lt;h3&gt;8am-9pm&lt;/h3&gt;&lt;/div&gt; </code></pre> <p>jQuery/Javascript/Idon'tevenknowanymore:</p> <pre><code>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' } </code></pre> <p>The trouble is that if I was going to change the color in the css I would use: </p> <pre><code> #Friday h3 {color:#DB35B0;} </code></pre> <p>which doesn't seem to work in the Javascript like this:</p> <pre><code> else if (day == 5) { document.getElementById('Friday h3').style.color='#DB35B0' } </code></pre> <p>I also tried:</p> <pre><code> else if (day == 5) { document.getElementById('Friday').children.style.color='#DB35B0' } </code></pre> <p>But that did nothing.</p> <p>So what do I do?</p> <p>Is it possible to target the children of the divs and change their color?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload