HTML Code: In this section, we will create a basic structure of the body. The body section contains an <div> element whose background color will be changed when the mouse moves over the div element.
Example: In this example, we will see the change of background color while mouse move over.
CSS Code: In this section, we will use some CSS property to style the div element.
Step 1: The first step is to create an array consisting of different colours.
Step 2: The second step is to use the querySelector() method to select the div element and then use addEvenListener() method to attach an event handler (mouseover) to it.
Step 3: In the last step, we will style the background of the div element using some logic i.e. we will use Math.random() function on the array to return a floating-point number between the array range then use Math.floor() method to round the floating number downward to its nearest integer.
Complete Code: In this section, we will combine the above three code sections.
Please Login to comment...