I have a Javascript project that I am working on that tests a string to see if it's a palindrome and that displays an answer
function displayResult(test) {
console.log('displayResult called on', test)
if(palindrome(test)){
console.log('it is a palindrome!')
document.getElementById('answer').innerHTML ="<h2 id='rightAnswer'> You made a palindrome!</h2>"
} else {
console.log("that's not a palindorm you dumbass")
document.getElementById('answer').innerHTML ="<h2 id='wrongAnswer'> Boy... you screwed that up</h2>"
}
}
As you can see above, the function inserts an H2 tag that includes an ID for either #rightAnswer or #wrongAnswer then I have CSS that I want to set up to edit both answers.
#wrongAnswer h2{
color: red;
}
#rightAnswer h2{
color: green;
}
However, when I test the code above, it doesn't show the answer as red or green. Is it possible to set up my CSS file to target IDs that are inserted by JS? I'd like to avoid using inline styling if possible.