0

I have an iframe list like that:

<iframe src="foo">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>
<iframe src="bar">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>
.
.
.
<iframe src="baz">
    <button class="dissmiss">Close</button>
    <script>
        // Do job here...
    </script>
</iframe>

How can I get the iframe with js or jquery? I want to remove the iframe when the button is clicked:

parentIframe.remove();

PS: They have same domain.

Yves
  • 3,752
  • 4
  • 29
  • 43

2 Answers2

1

From any iframe window (if not cross-domain) you can refer to the iframe HTMLElement on the parent page with

window.frameElement

When using this, you don't need to know id or class of the iframe, or count iframe tags within a parent document.

Teemu
  • 22,918
  • 7
  • 53
  • 106
0

If you want to access the content of an Iframe: Try to assign some unique id to the iframe.

Try this, hope it will work

 parent.$('body').find('Iframe').html();
nrsharma
  • 2,532
  • 3
  • 20
  • 36