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:
alert(this.parentElement);
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.
Thanks.
parentElementis not supported in Firefox < 9. It started life as a non-standard property of elements in IE 4 and has relatively recently been standardized in DOM4.Use
parentNodeinstead.