Here is the code I'm using to get the background image of selected div from below code
let now = new Date().getHours() * 100 + new Date().getMinutes();
let times = [1015, 1100, 1145, 1230, 1315, 1700, 1750, 1800];
let ids = ['r1', 'r3', 'r5', 'r7', 'r9', 'r11', 'r13'];
let selected = ids[times.reduce((acc, curr, idx) => now >= curr ? idx : acc)];
if (selected)
document.getElementById(selected).parentElement.style.backgroundImage = "url('images/g.gif')";
How can I even change the font color of same div which is selected? I tried using this
if (selected)
document.getElementById(selected).parentElement.style.backgroundImage = "url('images/g.gif')";
document.getElementById(selected).parentElement.style.color = 'red';
but as I had expected, it didn't work out.
Here is the fiddle https://jsfiddle.net/BlueYeti/yy2nLpg2/3/
Any help will be much appreciated.
selectedgives a valid output and finds an element in the DOM. Could you edit the question to include a working snippet? Although note your question states you want to get the colour, yet you appear to be setting it