Hi everyone,
I'm trying to dynamically create an image map for a particular image
on my website, and I'm running into an issue where I try to register
the "mouseover" and "mouseout" events for the AREAs of my image map.
Here is an abbreviated version of my code:
------------------------
function createImageMap() {
Â* Â*var divParent = document.getElementById("divParent");
Â* Â*var newMapNode = document.createElement("map");
Â* Â*// set name, id attributes for the newly created map node
Â* Â*for (var i = 0; i < arrayOfPoints.length; i++) {
Â* Â* Â* Â*var mapElement = arrayOfPoints[i];
Â* Â* Â* Â*var areaNode = document.createElement("area");
Â* Â* Â* Â*// set the alt, nohref, shape, coords attributes for the area node
Â* Â* Â* Â*var showMouseOverFunc = function(evt) {
Â* Â* Â* Â* Â* Â*showMouseOver(evt, mapElement);
Â* Â* Â* Â*};
Â* Â* Â* Â*var hideMouseOverFunc = function(evt) {
Â* Â* Â* Â* Â* Â*hideMouseOver(evt);
Â* Â* Â* Â*};
Â* Â* Â* Â*if (areaNode.addEventListener) {
Â* Â* Â* Â* Â* Â*areaNode.addEventListener("mouseover", showMouseOverFunc, false);
Â* Â* Â* Â* Â* Â*areaNode.addEventListener("mouseout", hideMouseOverFunc, false);
Â* Â* Â* Â*} else if (areaNode.attachEvent) {
Â* Â* Â* Â* Â* Â*areaNode.attachEvent("onmouseover", showMouseOverFunc);
Â* Â* Â* Â* Â* Â*areaNode.attachEvent("onmouseout", hideMouseOverFunc);
Â* Â* Â* Â*} else {
Â* Â* Â* Â* Â* Â*areaNode.onmouseover = showMouseOverFunc;
Â* Â* Â* Â* Â* Â*areaNode.onmouseout = hideMouseOverFunc;
Â* Â* Â* Â*}
Â* Â* Â* Â*newMapNode.appendChild(areaNode);
Â* Â*}
Â* Â*divParent.appendChild(newMapNode);
Â* Â*document.getElementById("imgMap").setAttribute(" usemap", "#map");
}
------------------------------
I've tested this in Firefox 2, and it works just fine with the DOM
Level 0 and 2 event models; the events appear to be registered with
their respective area elements and fire when I mouse over and out of
those areas.
However, when I try to run the same code in IE6, the events do not
appear to be registered at all. Â*I've tried sticking an alert() call
inside the functions that are to be called when the events fire and
had no luck. Â*I've also tried using the Level 0 event model (i.e. in
the else-clause) instead of IE's attachEvent() method and had no luck
either.
Can anyone please help me on this issue?
Sincerely,
Andrew