I am facing a small problem when I am trying to use functions written in JavaScript to change the styles of a <div>
block, which has an id of 'div4'. I found that this code cannot work normally. The <div>
was not shown when I ran these codes. Where's the problem?
function togreen() {
document.getElementById('div4').style.width = '200px';
document.getElementById('div4').style.height = '200px';
document.getElementById('div4').style.backgroundColor = 'green';
}
function tored() {
var DIV4 = document.getElementById('div4');
DIV4.style.width = '100px';
] DIV4.style.height = '100px';
DIV4.style.backgroundColor = 'red';
}
window.onload = function() {
var DIV = document.getElementById('div4');
DIV.onmouseover = togreen;
DIV.onmouseout = tored;
};
<div id="div4"></div>