Each element has a style property that helps in manipulating CSS properties. One of those CSS properties is the backgroundImage property which can be used to get the background image and set an image as background.
In the following example, we have a div element with 1.jpg as its background image. On mouse hover, we will change the background image to 2.jpg. Please have a look over the code example and the steps given below.
HTML & CSS
We have an images folder with 2 images 1.jpg and 2.jpg. You can use any 2 images of your choice.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.