Ovako dodajem event listener img objektu:
Code:
img.setAttribute("src", "images/"+image_name+".png");
if( img.addEventListener )
{
img.addEventListener('click',
function ()
{
if (this.className == "")
this.className = this.className.replace("", "semitrans");
else
this.className = this.className.replace("semitrans", "");
already_exist = false;
for(id in markers)
{
if (markers[id].type == pointData.type && markers[id].sport == pointData.sport)
{
if (markers[id].visible)
{
markers[id].hide();
this.setAttribute("src", "images/gray-"+markers[id].type+".png");
//document.getElementById(image_id).style.opacity = 0.4;
}
else
{
markers[id].show();
this.setAttribute("src", "images/"+markers[id].imagename+".png");
//document.getElementById(image_id).style.opacity = 1;
}
already_exist = true;
}
}
//if (already_exist)
return false;
}
,false);
}
else if( img.attachEvent )
{
img.attachEvent('onclick',function(e)
{
if (img.className == "")
img.className = img.className.replace("", "semitrans");
else
img.className = img.className.replace("semitrans", "");
already_exist = false;
for(id in markers)
{
if (markers[id].type == pointData.type && markers[id].sport == pointData.sport)
{
if (markers[id].visible)
{
markers[id].hide();
img.src = "images/gray-"+markers[id].type+".png";
//img.setAttribute("src", "images/gray-"+markers[id].type+".png");
//document.getElementById(image_id).style.opacity = 0.4;
}
else
{
markers[id].show();
img.src = "images/"+markers[id].imagename+".png";
//img.setAttribute("src", "images/"+markers[id].imagename+".png");
//document.getElementById(image_id).style.opacity = 1;
}
already_exist = true;
}
}
//if (already_exist)
return false;
});
}
img.setAttribute("src", "images/"+image_name+".png");
if( img.addEventListener )
{
img.addEventListener('click',
function ()
{
if (this.className == "")
this.className = this.className.replace("", "semitrans");
else
this.className = this.className.replace("semitrans", "");
already_exist = false;
for(id in markers)
{
if (markers[id].type == pointData.type && markers[id].sport == pointData.sport)
{
if (markers[id].visible)
{
markers[id].hide();
this.setAttribute("src", "images/gray-"+markers[id].type+".png");
//document.getElementById(image_id).style.opacity = 0.4;
}
else
{
markers[id].show();
this.setAttribute("src", "images/"+markers[id].imagename+".png");
//document.getElementById(image_id).style.opacity = 1;
}
already_exist = true;
}
}
//if (already_exist)
return false;
}
,false);
}
else if( img.attachEvent )
{
img.attachEvent('onclick',function(e)
{
if (img.className == "")
img.className = img.className.replace("", "semitrans");
else
img.className = img.className.replace("semitrans", "");
already_exist = false;
for(id in markers)
{
if (markers[id].type == pointData.type && markers[id].sport == pointData.sport)
{
if (markers[id].visible)
{
markers[id].hide();
img.src = "images/gray-"+markers[id].type+".png";
//img.setAttribute("src", "images/gray-"+markers[id].type+".png");
//document.getElementById(image_id).style.opacity = 0.4;
}
else
{
markers[id].show();
img.src = "images/"+markers[id].imagename+".png";
//img.setAttribute("src", "images/"+markers[id].imagename+".png");
//document.getElementById(image_id).style.opacity = 1;
}
already_exist = true;
}
}
//if (already_exist)
return false;
});
}
e sada hocu da uklonim taj event.
Kako da to uradim?