How to change the class of an HTML element using JavaScript?
Hello everyone! I just started learning JavaScript and I can't figure out how to change classes of elements on the page. I have a simple HTML structure:\n\n```html\n\n
This is a block
\n```\n\nI want that when clicking the button, the div's class changes from "red" to "blue" (i.e., the color changes from red to blue). I tried writing something like `document.getElementById('myDiv').class = 'blue'`, but it doesn't work. The console shows an error: "Uncaught TypeError: Cannot set properties of null". Although the element definitely exists on the page, I checked.\n\nThen I found out that I need to use `className`, but when I write `document.getElementById('myDiv').className = 'blue'`, the element loses the "box" class, and I need it to remain.