how do I know if the mouse pointer is on the HTML element?

I have a timed event I want to behave differently accordingly to what HTML element the mouse pointer is on. Is there a way, assuming I have the HTML element, to know if the mouse pointer is currently on top of it. I am well aware of the onmouseover/onmouseout events and how to use them. I am using JQuery. I am obviously looking for some kind of flag, as I need to check a state and not handle an event. <strong>again, I know how to implement this with events.</strong>


I'm not aware of any built-in way to ping an element for the status of mouse hovering.

However, you can create one by updating a flag at mouseenter and mouseleave -- which is where Brian Driscoll's suggestion of .hover comes in:

jQuery.fn.tracking = function () { this.data('hovering', false); this.hover(function () { $(this).data('hovering', true); }, function () { $(this).data('hovering', false); }); return this; }; jQuery.fn.hovering = function () { return this.data('hovering'); }

You'll need to initialize tracking for each element you care about:


But then you can get the status of any of them:

if ($('#elem1').hovering()) { // ... } else if ($('#elem2').hovering()) { // ... }

Demo: http://jsbin.com/amaxu3/edit


Have you looked into jQuery.hover()? http://api.jquery.com/hover/


You need to give name to html andme and on mouseover you need to check document.getelementsbyName. Then check what your are getting as output. Now you can take decision is it html control or asp.net.

When you use collObjects = object.getElementsByName("htmlcontrol") then compare id of both.

1 morething why you needed to check this in javascript. there may be some other solution for that. Just share with us.


You might have some luck with document.elementFromPoint, although I believe there are some inconsistencies in older browser implementations (http://www.quirksmode.org/dom/w3c_cssom.html#documentview).

$('#elem').mousemove(function(e){ if (this == document.elementFromPoint(e.clientX, e.clientY)) { // Do stuff } });

Or outside of a handler

if ($('#elem').get(0) == document.elementFromPoint(x, y)) { // Do stuff }

Aside from that, the only other option that comes to mind is using event handlers to keep track of which element the mouse is over.


  • WIX If…else condition using registry
  • Simulate inheritance using functional programming in React Redux application
  • How to simplify multiple if-else-if statements in c++
  • Is OracleDataSource.getConnection thread-safe?
  • Outer Glow Effect and rotation On A Label in WPF
  • SpringMVC: how to get the value of @RequestMapping in the function
  • Footer's nav submenu won't stay open after I mouse out unless I mouse over quickly and hov
  • Display height in bokeh vbar tooltip
  • Powershell Regex to replace XML tag values
  • AnalyticsReceiver in Google Analytics Tracking
  • Custom variables on product details page in Magento
  • staticfiles and STATIC_URL with virrtualenv - django
  • how to handle large size of update query in mysql with laravel
  • How to use both ga.js and analytics.js?
  • How to emulate integrated numeric keypad cursor keys in linux
  • doubleValue does not convert the object to a double value correctly at all times
  • How to show a specific VC , more like navigate to a stack of VC
  • jQuery file download plugin
  • Update SQL MS Access 2010
  • How to edit css for jquery datepicker prev/next buttons?
  • Adding independent aspx/asmx pages into DotNetNuke
  • How do you remove the JComboBox 'click and see dropdown' functionality?
  • Is it safe to drop the -webkit vendor prefix from the css3 border-radius yet?
  • if some function is not optimized does it mean that all functions where it is declared are not optim
  • Why doesn't a local variable live long enough for thread::scoped?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • Other than Linq to SQL does anything else consume INotifyPropertyChanging?
  • how do i write assembly code from c#?
  • Ajax Upload File: $_FILES is empty but files exists in request header
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • Can I check if a recipient has an automatic reply before I send an email?
  • Change multiple background-images with jQuery
  • jQuery tmpl and DataLink beta
  • Comma separated Values
  • How to disable jQuery.jplayer autoplay?
  • Error creating VM instance in Google Compute Engine
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • Hits per day in Google Big Query
  • how does django model after text[] in postgresql [duplicate]
  • Setting background image for body element in xhtml (for different monitors and resolutions)