Skip to content
the poor coder

get an element from outside of iframe jquery

Poor Man
Published
Reading time
1 min read

Get an Element from Outside of iFrame jQuery#

If you have an iFrame in your HTML document and you want to access the elements outside of it using jQuery, you can do so by using the parent() method. This method is used to access the parent document of an iFrame. Here's how:

JavaScript

var element = parent.$('#element-id');

In the above code, $ is used to access jQuery and '#element-id' is the ID of the element that you want to access.

If you want to access an element that is higher up the DOM tree, you can chain the parent() method. For example:

JavaScript

var element = parent.parent().$('#element-id');

In the above code, parent() is used twice to access the grandparent document of the iFrame.

If you have multiple iFrames on your page and you want to access an element outside of a specific iFrame, you can use the siblings() method to target the element you want. For example:

JavaScript

var element = parent.$('#iframe-id').siblings('#element-id');

In the above code, '#iframe-id' is the ID of the iFrame and '#element-id' is the ID of the element that you want to access.

Another way to access elements outside of an iFrame is by using the window.parent property. This property returns a reference to the parent window object. Here's how:

JavaScript

var element = window.parent.$('#element-id');

In the above code, window.parent is used to access the parent window object and $ is used to access jQuery.

By using one of these methods, you can easily access elements outside of an iFrame using jQuery.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC