find parent elements within an iframe

0

Good morning, I have a document with the following structure:

<div id=’Prueba’>
<iframe id=’myiframe1’>
    <div id=’div_Actual’></div>
</iframe>
</div>

I want to know if from the html page that is in the iframe, I can access the div element with id = 'Test' this to change the size of the element I want or manipulate it with css, I tried jquery in the following way but it does not work for me:      $ (this) .parent (). parent (). attr ('id');

    
asked by PolloKulos 06.11.2018 в 22:06
source

1 answer

1

To obtain the object of your father's body, you can do this:

var parentBody = window.parent.document.body

If you are in the same domain as your iframe from where you run the code, once you have it, you can use the javascript in that object:

window.parent.document.getElementById("ContainingiFrame").style.height = "400px";

or with jQuery:

$("#ContainingiFrame", parentBody).height("400");

Here is an article on how to resize an iframe from within the iframe with sample code: link

And, a related question / answer about resizing an iframe based on its own content: Resize an iframe based on content

Source: This response is a translation of Retrieving the iframe parent of a document in jQuery

    
answered by 07.11.2018 / 05:13
source