appendChild does not properly set parentElement
I may be misunderstanding the correct usage of this function, but I believe appendChild is working incorrectly in Firefox. I have a very large script that has worked fine in IE since version 6. We're now trying to make this script work in all browsers, so I'm starting to test in FF.
Here's some relevant lines from the script, modified for easier reading here:
var tempDocFragment = document.createDocumentFragment(); var tempNewtbody = document.createElement("tbody"); trElem = document.createElement("tr"); tdElem = document.createElement("td"); trElem.appendChild(tdElem); tempDocFragment.appendChild(trElem); tempNewtbody.appendChild(tempDocFragment); mytable.appendChild(tempNewtbody);
Code like the above runs within a loop that adds between 0 and 1000+ table rows to a table. This all appears to work fine and the table rows appear in the table. However, the table rows have an onmouseover event that runs this line of code:
This returns 'undefined' in Firefox, but returns the proper parentElement on IE. So it appears that Firefox is running the code to append the child elements correctly, but somehow fails to associate any parent with those child elements. I would appreciate any insight into what I may be doing wrong.
Use parentNode instead.
the standard way is to use parentNode, it will work on all browsers