I've created a calendar application for the website I'm building and I'm trying to remove a div element with javascript.
The Process
-------------------
* Calendar Page Loads
* User clicks on an event
* Event pops up with a Fancybox window which is passed the Container Div ID, and Event Div ID
* User clicks Remove Event
* The div specified (calendar event div) is supposed to be removed
The javascript code I'm using is :
<script language="javascript" type="text/javascript">
function btnClick(container, objID) {
removeElement(container, objID);
parent.$.fancybox.close();
}
function removeElement(par, div) {
var d1 = parent.document.getElementById(par);
var d2 = parent.document.getElementById(div);
d1.removeChild(d2); // The Problem Line DOM 8 Not Found Exception
}
</script>
Using an alert shows that d1 and d2 are found, however I get a DOM 8 exception when the child node is being removed. Any idea how to get this to work?
EDIT :
I'm using ASP.Net so this code is run on Page_Load
if(Request.QueryString["Container"] != null)
lnkDelete.Attributes.Add("onclick", "btnClick(\"" +
Request.QueryString["Container"].ToString() + "\",\"" +
Request.QueryString["Control"].ToString() + "\");");
So it basically just adds the btnClick
function to the Remove Event link button.
The event does fire, and the elements are found, it's just that it won't remove the child element from the parent document.