views:

1873

answers:

4

Is it possible using jQuery (or any other JavaScript function) to detect when an onmouseover event is fired?

I have a page where existing javaScript calls a onmouseover/out events to re-write the contents of the div. I'm actually only interested in getting at what the div contains while the mouse is hovered over it. The onmouseover event is generated server-side by a program I don't have the ability to change :(.

Any suggestions on how to accomplish this?

+2  A: 
$("#idOfYourControl").hover(function() { /*mouseover event*/ }, function() { /*mouseout event*/ });
Brandon Montgomery
+1  A: 

You can use the mouseover event handler in jQuery.

http://docs.jquery.com/Events/mouseover#fn

wschenkai
+1  A: 

Here's an even more specific example:

$("#idOfYourControl").hover(
   function() { $('#divToShowText').text($(this).text()) }, 
   function() { $('#divToShowText').text("") }
);
altCognito
+1  A: 

Depending on how the server is writing the original mouseover handler out, you can use a simple overwrite to add your own hook that you can then use to detect the old one being fired:

var oldHandler = yourElement.onmouseover;
yourElement.onmouseover = function() {
    //Do whatever new code you want here...
    $j.trigger('oldHandlerCalled');

    oldhandler();
}

Kind of a quick and dirty example, but you get the idea. No guarantees that this won't leak memory in IE6 ;)

If the server is attaching the event via jQuery, you can look in yourElement.data.events and do it in a much tidier way than this.

dfltr