Skip to content
Advertisement

make div appear on mouse over

I am trying to make a div .description that appears where the mouse is as it hovers over an element.

So far, I have this code for making the div appear in a fixed location:

JavaScript

It works fine, but instead of just have .description appear, I need it to appear where the mouse hovers.

I tried adding this function:

JavaScript

but it didn’t work. I also tried adding the line within the function but i’m not sure how to pass the event argument.

Please see my JSfiddle: https://jsfiddle.net/bns4zp1q/2/

Advertisement

Answer

You can listen to the mousemove event, and use your divPosition function.

https://jsfiddle.net/agbuLop1/

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement