I'm learning JavaScript and want to pull a value from between HTML tags. In my code, I'm checking if the text matches 'Ready' and changing the background color to green if it does; otherwise, it should turn red and alert me of the checked value. However, the expected result isn't being produced. Here's a snippet of what I'm working with:
```html
| Ready |
if (document.getElementById('statusBox').nodeValue == 'Ready') {
document.getElementById('statusBox').style.backgroundColor = 'green';
} else {
document.getElementById('statusBox').style.backgroundColor = 'red';
alert(document.getElementById('statusBox').nodeValue);
}
```
5 Answers
It’s surprising you went with `nodeValue`. I rarely use it for the DOM. You might want to use either `innerText` or `textContent` instead. They are easier to work with for your case!
Much appreciated! I was just googling around and experimenting with different things in my IDE until I figured it out. That's how I got here, lol.
MDN is life for learning web development!
Have you tried using `.innerHTML`? That's the way to go if you're trying to get text between tags!
You should definitely check out structured learning resources like the MDN guides. They're super helpful for understanding how to work with HTML and JavaScript!

That did it. Thanks!