Skip to content
Advertisement

How to apply hover effect on images?

I have used spotlight package and customized it,i want the hover effect in div, when i hover it, the search button appears, when i remove my cursor,the button disappears.

For this i am using mouseover and mouseout event in addEventListener.

Html:

JavaScript

Following is the js code which i am using to build this logic for every element through loop.

JavaScript

The problem is that the above js code is only working for last div element rather applying this hover effect on all the elements.

style.css

JavaScript

So, how can i run it for all the div elements through loop?

Advertisement

Answer

Rather than making things complex with javascript you can try using css to achieve the same result. I have given an example where with a simple one line of css you can do what it took more than 18 lines of javascript code

JavaScript
Advertisement