Search code examples
javascriptonclickdom-eventsonmouseover

How do you register an onclick event while having onmouseover using Javascript


I have a function that tracks the user's mouse to show them visually where they are on an x,y grid. When the user's mouse is over the image, a function is called via onmouseover="gridFunction();".

The problem is that I want to record the user's click (onclick or onmousedown) as they move around the grid image. So I'm trying to stack an onclick with an onmouseover.

Any suggestions? I tried creating document.onclick = "clickFunction();" but for some odd reason this never gets called when I click on the website (even when I'm not hovering over the image).


Solution

  • I would recommend using jQuery's events api - it is very easy to use and will more than likely be able to handle your situation.