Johnny000 Johnny000 - 4 months ago 25
jQuery Question

jquery get element where the cursor is

I'm building a splittesting tool for my website with javascript and jquery. Now I want to show for each elements I want to splittest a little hovermenu when the cursor passes over the element in my previewbox. Is there any possibility to do something like this ? I treid something like this

$('body').hover(function(event){
console.log(event.target.nodeName);
// to see if it's showing up the element
});


but it's only triggering once. As I don't want to use click since I want also to showup the menu on anchor elements I'm a bit lost

Answer

I believe you want to use the mousemove event here instead of the hover event.

$('body').mousemove(function(evt){
    console.log(evt.target);
});

Just remember to use mousemove with extreme caution.

See an example here.