PDA

View Full Version : replacechild not working in ie7


djstaz0ne
02-11-2010, 03:24 AM
replacechild is not working properly in ie7. I have looked around and have found no workaround. :confused: the following script works in ff, but not in ie:

Note: this code is stripped down to the bare minimum
This function is applied to all elements with a specific name using a for loop


function encloseElement(e){
cDiv = document.createElement('div');
cDiv.innerHTML = '<div style="width:50px; height:50px; background-color:#000000;">&nbsp;</div>';
e.parentNode.replaceChild(cDiv, e);
}


Here is the loop used to cycle thru the elements


function drawPage(){
ctDivs = document.getElementsByName("content");
ctTopDivs = document.getElementsByName("ctTop");
rs = "";
for(i=0; i<ctDivs.length; i++){
encloseElement(ctDivs.item(i));
}
for(j=0; j<ctTopDivs.length; j++){
encloseElement(ctTopDivs.item(j));
}
}


Any help is appreciated.

A1ien51
02-11-2010, 04:20 AM
Any error messages?

Eric

djstaz0ne
02-11-2010, 04:34 AM
no errors

djstaz0ne
02-13-2010, 12:03 AM
Help plz..:D

Fang
02-13-2010, 08:47 AM
drawPage looks wrong; getElementsByName is returned to ctDivs, a list of divs, surely not.
In the loop the items are iterated, ctDivs.item(i), I think ctDivs[i] is what you want to do.

hdewantara
02-14-2010, 08:54 PM
Probably because IE7 is still using parentElement instead of parentNode?