I get this script error “Invalid argument” when using appendChild(). When in Microsoft Visual Studio Debugger I see “htmlfile: Invalid argument”, and the line it blows up on is t.appendChild(n);

The div I want to append the child div to is the top most div in the dom.
Anyone see what I am doing wrong here?

var t = document.parentWindow.parent.parent.document.getElementById("mod"); 
var n = document.createElement("div");
n.setAttribute("id", "c_dlg"); 
t.appendChild(n);

Thanks

Could you post the corresponding HTML code?

This is late reply to this post but it might help someone searching with this problem.

I found that creating the new element within the same document I needed to append to fixed a similar problem I was having.

So in this case creating the new div like this may be a fix for this problem:

document.parentWindow.parent.parent.document.createElement("div");

Hope this helps someone.

This is late reply to this post but it might help someone searching with this problem.

I found that creating the new element within the same document I needed to append to fixed a similar problem I was having.

So in this case creating the new div like this may be a fix for this problem:

document.parentWindow.parent.parent.document.createElement("div");

Hope this helps someone.

This solved my problem, thanks!

This is late reply to this post but it might help someone searching with this problem.

I found that creating the new element within the same document I needed to append to fixed a similar problem I was having.

So in this case creating the new div like this may be a fix for this problem:

document.parentWindow.parent.parent.document.createElement("div");

Hope this helps someone.

After a long search, i got this post and my problem is solved.

Thanks,
Suresh
<FAKE SIGNATURE>