Forum Moderators: open
I'd rather not use an array with the URLs - trying not to disrupt current work flow.
var getandsetareamaplinks = function(){
var areas = document.getElementsByName('planetmap')[0].children;
for (var i = 0; i < areas.length; i++) {
var a = document.createElement('a');
a.setAttribute('id', 'item' + i);
a.setAttribute('href', areas[i].href);
a.setAttribute('target', '_blank');
a.setAttribute('class', 'myclass');
a.innerHTML = areas[i].alt || 'Click here :)'; // set alt!
document.getElementById('mydiv').appendChild(a);
a.addEventListener('click', function() {
alert("hello!");
return false;
//clickTracker._trackEvent('event_category', 'event_label');
});
}
};
// If you have your own onload handler you can get rid of the rest
// of this simple onload handler stuff
function addLoadEvent(func)
{
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function()
{
if (oldonload) {
oldonload();
}
func();
};
}
}
addLoadEvent(getandsetareamaplinks);
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
<div id="mydiv"></div>