views:

466

answers:

2

Hi, could someone help me to understand why this errors

document.getElementById("actContentToGet").contentWindow.document.body.getElementById is not a function

function deleteElement(element){
  var elementID = $(element).attr("class");
  alert(elementID);
  document.getElementById('actContentToGet').contentWindow.document.body.getElementById(elementID).remove;
  alterContent();
  giveAllIDs();
  hoverLoad();
 }
+3  A: 

Try changing this:

...contentWindow.document.body.getElementById(elementID)...

to this:

...contentWindow.document.getElementById(elementID)...


Edit from comments: It's not removing that element because that's not how you remove elements. Try this:

var iframe = document.getElementById('actContentToGet');
var frameDoc = iframe.contentDocument || iframe.contentWindow.document;
var el = frameDoc.getElementById(elementID);
el.parentNode.removeChild(el);

See the documentation here.

nickf
That seems to be getting the element object but is not removing it.. any ideas why?document.getElementById('actContentToGet').contentWindow.document.getElementById(elementID).remove;
Phil Jackson
editing the answer...
nickf
Your a star thank you!!!
Phil Jackson
`contentWindow` is a non-standard IE extension. For compatibility use: `var idoc= iframe.contentDocument || iframe.contentWindow.document`.
bobince
thanks bobince, that's been added to the answer now.
nickf
+1  A: 

Try removing the body.- getElementById() is a document. function.

Pekka