Having discovered that IE does not handle javascript onmouseout, I’m determined to use jQuery instead so the cross-browser compatibility would be taken care of automatically. I am making an area defined by an svg path light up when the mouse hovers over it, and I adapted the code provided on the Raphael website from the Australia example.
In this code, each state of Australia is defined by a Raphael path, for example Tasmania:
aus.tas = R.path("...").attr(attr);
This path (‘st’) is then passed to the function:
st[0].onmouseover = function () {
...
};
Contrary to what I would have expected, the code is st[0].onmouseover as opposed to merely st.onmouseover. Thus, the path must actually be an array, and st[0], whatever that is, is the thing that is hovered over.
In order to replace onmouseover with the jQuery equivalent (which I believe is .mouseout()), I need to assign a class to st[0] so I can refer to it with jQuery. My question is, how do I do that? If the code was st.onmouseover it would be straightforward, but why is the path (st) an array? What exactly is st[0]? And how the heck do I get to it?
Note: That demo was made with an old version of Raphael. Now Raphael has its own custom event handlers including
.mouseover()and.hover().The short of it:
Simply wrap the DOM Object to make a jQuery Object out of it, or use the Raphael built in custom event handlers:
Or, probably more convenient, and IE supported:
Or, using a Raphael built in event handler method:
The long of it:
You can get the reference to the DOM object to work on using
nodeor[0], sinceRaphaelObject[0]is always the reference to the DOM element:So, with you function:
Additionally, I would suggest looking into the jQuery
.hover()function, which does handle IE quite nicely:As a simplified demonstration, here is how to bind
mouseenterandmouseoutusing.hover()to a Raphael element (tested in IE 8):Try it out with this jsFiddle
Additionally, the Raphael
.hover()method seem to work in IE too.