vendredi 16 octobre 2020

Access DOM inside iFrame using Javascript

I am trying to access a DOM element from my main page and want to update the CSS. I use the following;

var myIframeContainerEl = $('#myIframeContainerEl');
myIframeContainerEl.contents().find(".required").css("color", "#f0f0f0");

This is not working for some reason. While it is able to find "myIframeContainerEl", for some reasons, "myIframeContainerEl.contents()" shows a length of 0. Is the above not the correct way of doing it?

Also, just to add, I am using this in my Ember project and use it within didTransition hook and inside "afterRender" So the element is present when I am trying to access.




Aucun commentaire:

Enregistrer un commentaire