2009-12-13 12 views
7

qualcuno potrebbe aiutarmi a capire il motivo per cui questo erroregetElementById da iframe

document.getElementById ("actContentToGet"). ContentWindow.document.body.getElementById non è una funzione

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

risposta

18

Provare a cambiare:

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

a questo:

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

Edit dai commenti: Non è la rimozione di questo elemento, perché non è così che si rimuovono gli elementi. Prova questo:

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

Vedere il documentation here.

+0

La tua stella grazie !!! –

1

Provare a rimuovere il body. - getElementById() è una funzione document..