Bob90
05-09-2007, 07:53 AM
Hello again,
so, How do you add event handlers to DOM created elements in IE?
I have been using
//Add element via DOM
//Add <a> to <div>
var temp_obj = document.createElement("a");
temp_obj.setAttribute("id","id"+randId+"_a");
temp_obj.setAttribute("href",tempAr[0]);
temp_obj.setAttribute("target",tempAr[1]);
temp_obj.setAttribute("onmouseover",rolloverTxtOn+" "+scaleTxtOn+" ,goTo='"+tempAr[0]+"'");
temp_obj.setAttribute("onmouseout",rolloverTxtOff+" "+scaleTxtOff+" ,goTo=''");
document.getElementById("radialMenu").appendChild(temp_obj);
//alert(document.getElementById("id"+randId+"_a").onmouseover)
if(document.attachEvent && !document.addEventListener)
{
temp_obj = document.getElementById("id"+randId+"_a");
temp_obj.attachEvent("onmouseover",function(){rollover('id'+randId,picDir+tempAr[3]);highlight('id'+randId+'');goTo=tempAr[0];} );
temp_obj.attachEvent("onmouseout",function(){rollover('id'+randId,picDir+tempAr[2]);lowlight('id'+randId+'');goTo='';} );
}
rolloverTxtOn+scaleTxtOn+",goTo='"+tempAr[0]+"'";
//temp_obj.onmouseout = rolloverTxtOff+" "+scaleTxtOff+" ,goTo=''";
temp_obj = null;
Becasue the setAttribute does not seem to work in IE.
When I tried attachEvent, the handlers breaks and only works for the last dynamically created element. What I mean is that I have 9 elements and when I rollover them, they all call the rollover of the last element.
Thanks in advance
:)
so, How do you add event handlers to DOM created elements in IE?
I have been using
//Add element via DOM
//Add <a> to <div>
var temp_obj = document.createElement("a");
temp_obj.setAttribute("id","id"+randId+"_a");
temp_obj.setAttribute("href",tempAr[0]);
temp_obj.setAttribute("target",tempAr[1]);
temp_obj.setAttribute("onmouseover",rolloverTxtOn+" "+scaleTxtOn+" ,goTo='"+tempAr[0]+"'");
temp_obj.setAttribute("onmouseout",rolloverTxtOff+" "+scaleTxtOff+" ,goTo=''");
document.getElementById("radialMenu").appendChild(temp_obj);
//alert(document.getElementById("id"+randId+"_a").onmouseover)
if(document.attachEvent && !document.addEventListener)
{
temp_obj = document.getElementById("id"+randId+"_a");
temp_obj.attachEvent("onmouseover",function(){rollover('id'+randId,picDir+tempAr[3]);highlight('id'+randId+'');goTo=tempAr[0];} );
temp_obj.attachEvent("onmouseout",function(){rollover('id'+randId,picDir+tempAr[2]);lowlight('id'+randId+'');goTo='';} );
}
rolloverTxtOn+scaleTxtOn+",goTo='"+tempAr[0]+"'";
//temp_obj.onmouseout = rolloverTxtOff+" "+scaleTxtOff+" ,goTo=''";
temp_obj = null;
Becasue the setAttribute does not seem to work in IE.
When I tried attachEvent, the handlers breaks and only works for the last dynamically created element. What I mean is that I have 9 elements and when I rollover them, they all call the rollover of the last element.
Thanks in advance
:)