166
rated 0 times
[
171]
[
5]
/ answers: 1 / hits: 7880
/ 5 Years ago, sun, april 14, 2019, 12:00:00
I'm trying to add font awesome icons to my greeting function
so in every greeting title a different font awesome icon will be attached.
I tried doing it the traditional way but but javaScript prints the html as text and now the title looks like this:
Good Morning<i class=fas fa-sun></i>
```javascript
function goodSomething() {
let today = new Date();
let curHr = today.getHours();
if (curHr < 12) {
document.getElementById('greetings').innerText = Good Morning + '<i class=fas fa-sun></i>';
} else if (curHr < 18) {
document.getElementById('greetings').innerText = Good Afternoon + '<i class=fas fa-coffee></i>';
} else {
document.getElementById('greetings').innerText = Good Evening + '<i class=fas fa-moon></i>';
}
};
I expect the output of:
good morning + (sun icon)
good afternoon + (coffee icon)
good evening + (moon icon)
More From » dom