views:

41

answers:

1

Hi, i'm not really sure whats the problem here, it works with chrome and ff but not ie.

var newdiv = document.createElement("div");
newdiv.innerHTML = xhr.responseText;
el = newdiv.firstChild.nextSibling;
var next;
do{
next = addpoint.nextSibling;
if(next.className != "commentstyle golduser") break;
}while(addpoint = next);
document.getElementById("testimonialcommentlisting"+id).insertBefore(el,next);

error is at this line document.getElementById("testimonialcommentlisting"+id).insertBefore(el,next);


**UPDATE**

ok this is werid, i did some test and i found the problem. the problem is with var el for chrome and ff el is div element while ie is null.

here comes the weirder problem. By right, newdiv.firstChild should be the div element but i dont know why ff and chrome register it as a text element and clearly my responseText is something like this

<div>blahblah</div>

i hope somebody understands what i'm talking about.

+1  A: 

Your loop follows an odd construction. You're fetching addpoint.nextSibling then looking at its className attribute, and only then checking to see if the node is valid. This means on the last iteration through the loop, when next is null, you're trying to access the className property of null.

while (next) {
    if (next.className != 'commentstyle golduser') break;
    next = next.nextSibling;
}

Without more context from what surrounds this loop I don't know how addpoint fits in. It's not necessary just to make the loop work, though if you do need to change addpoint there's no reason you can't do so using this loop construction.

The point is that you are never checking next.className when next is null.

VoteyDisciple
good catch - that's probably the problem.
Pointy
hi sir, my do loop is doing fine, i checked it many times. and i mistaken error is at this line document.getElementById("testimonialcommentlisting"+id).insertBefore(el,next);
john
In that case, what is `id`? It's not defined in the code you shared. Have you checked to see if `document.getElementById()` is returning a valid node for the value you're giving it in IE?
VoteyDisciple
new discovery to my problem
john