0

I'm trying to change the elements in an I frame using JavaScript and it is not working! I have used it before to do this just not within an Iframe.

Console says Uncaught TypeError: Cannot read property 'textContent' of null at HTMLIFrameElement.iframe.onload

$( document ) .ready (function() { 


    var iframe = document.getElementById("<%= iframeID.ClientID%>");

    iframe.onload = function () {
        console.log("Loaded");
    var doc = iframe.contentWindow.document;

    console.log(doc.getElementsByClassName("fc-title"));
    console.log(doc.getElementsByClassName("fc-title").item(0).textContent);
    
    var ele = doc.getElementsByClassName("fc-title");
    
    for (var i = 0; i < ele.length; i++) {
    console.log(ele[i].textContent || ele[i].innerText);
    }
  }

})
  • Does this answer your question? [How can I access iframe elements with Javascript?](https://stackoverflow.com/questions/1452871/how-can-i-access-iframe-elements-with-javascript) – Brian Lee Nov 13 '20 at 04:36
  • What does the previous log outputs? What if you replace this previous call with `console.log([...doc.getElementsByClassName("fc-title")])`? The elements you are targetting doesn't exist when the code is ran. – Kaiido Nov 13 '20 at 05:14

0 Answers0