Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 433
Johnny000 Avatar asked Jan 22 '13 17:01

Johnny000


People also ask

How to find the cursor position in jQuery?

Answer: Use the jQuery event. pageX and event. pageYpageX and event. pageY in combination with the jQuery offset() method to get the position of mouse pointer relative to an element.

How to get element position in jQuery?

jQuery position() MethodThe position() method returns the position (relative to its parent element) of the first matched element. This method returns an object with 2 properties; the top and left positions in pixels.

How can I tell if a div has a cursor?

You can simply use the CSS :hover pseudo-class selector in combination with the jQuery mousemove() to check whether the mouse is over an element or not in jQuery. The jQuery code in the following example will display a hint message on the web page when you place or remove the mouse pointer over the DIV element's box.

How do I know where my mouse is?

Once you're in Mouse settings, select Additional mouse options from the links on the right side of the page. In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK. To see it in action, press CTRL.


1 Answers

If you are using the keyboard and not the mouse: Not jQuery, just plain JavaScript for those who are interested:

getSelection().getRangeAt(0).commonAncestorContainer.parentNode
like image 112
Stephani Bishop Avatar answered Oct 01 '22 01:10

Stephani Bishop