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: 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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With