The mouseover event triggers when the mouse pointer enters an element, while the mouseout event triggers when the pointer leaves the element.
Your task in this problem is to apply javascript on the div with id of 'hoverBox' that changes the styling of the box.
Refer to the table below for the instructions.
| Step No | Crucial Component | Instruction | code instruction |
|---|---|---|---|
| 1 | div#hoverBox | Select it with document.getElementById | code : const hoverBox = document.getElementById('hoverBox') |
| 2 | mouseover (javascript event) | add event listener to the hoverBox variable (created in step 1) | code: hoverBox.addEventListener('mouseover',()=> { // step 3, 4 & 5 here }) |
| 3 | inside the event listener function (added in step 2) | set the #hoverBox's background color to "#FF5733" |
hoverBox.style.backgroundColor = '#FF5733' |
| 4 | inside the event listener function (added in step 2) | transform the #hoverBox to scale 1.1 times |
hoverBox.style.transform = 'scale(1.1)' |
| 5 | inside the event listener function (added in step 2) | set the #hoverBox's textContent to "Mouse Over" |
hoverBox.textContent = 'Mouse Over!' |
| 6 | mouseout (javascript event) | add another event listener to the hoverBox variable (created in step 1). this time the event should be 'mouseout' event | code: hoverBox.addEventListener('mouseout',()=> { // step 7,8 & 9 to be written here }) |
| 7 | inside the event listener function (added in step 6) | set the #hoverBox's background color to "#4CAF50" | hoverBox.style.backgroundColor = '#4CAF50' |
| 8 | inside the event listener function (added in step 6) | transform the #hoverBox to bring it back to its original state | hoverBox.style.transform = 'scale(1)' |
| 9 | inside the event listener function (added in step 6) | set the #hoverBox's textContent to "Hover over me!" |
hoverBox.textContent = 'Hover over me!' |
Best of luck, developers!