138
rated 0 times
[
145]
[
7]
/ answers: 1 / hits: 15423
/ 4 Years ago, thu, october 8, 2020, 12:00:00
I wanted to change the color of the heading during specific times of the day.(e.g At night blue, in the morning green...)
For this I'm trying to use inline-css(inside js file).
My css file:
.heading {
font-size: 50px;
font-weight: bold;
border-bottom: 5px solid black;
}
My js file:
import React from "react";
import ReactDOM from "react-dom";
const root = document.getElementById("root");
const curretnTime = new Date().getHours();
if (curretnTime < 12 && curretnTime >= 0) {
ReactDOM.render(
<div>
<h1 className="heading">Good Morning</h1>
</div>,
root
);
} else if (curretnTime >= 12 && curretnTime <= 18) {
ReactDOM.render(
<div>
<h1>Good Afternoon</h1>
</div>,
root
);
} else {
ReactDOM.render(
<div>
<h1>Good Evening</h1>
</div>,
root
);
}
I know it is pretty easy question to ask, but any answer would be helpful. Thank you.
More From » html