Home > Web Front-end > JS Tutorial > How to get iframe with jquery

How to get iframe with jquery

coldplay.xixi
Release: 2020-12-01 16:28:59
Original
5273 people have browsed it

Jquery method to obtain iframe: Add jquery selector outside the dom method, the code is [$(window.frames["iframeChild"].document),$(window.parent.document)].

How to get iframe with jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

How to get iframe with jquery:

In the following web page, some people will use iframe. It is very simple for dom to get the iframe in the page:

Operation iframe in the parent window:

window.frames["iframeChild"].document    //假如iframe的id为iframeChild
Copy after login

Operation of the parent window in the child window: window.parent.document

Then, use the method if you want to use jquery , how do we use jquery to get iframe? Here's how to collect it.

Getting the object of the page is actually adding the jquery selector outside the dom method:

Operation iframe in the parent window:

$(window.frames["iframeChild"].document)    //假如iframe的id为iframeChild
Copy after login

Operation of the parent window in the child window:$(window.parent.document)

You can continue to obtain the dom in the iframe.

There are two ways to get the DOM object in the iframe

  • $(window.frames["iframeChild"].document).find("#child")

  • $("#child",window.frames["iframeChild"].document)

1.In Operate in the parent window to select all radio buttons in the IFRAME

$(window.frames["iframeChild"].document).find("input[@type='radio']").attr("checked","true");
Copy after login

2. Operate in the IFRAME to select all radio buttons in the parent window

$(window.parent.document).find("input[@type='radio']").attr("checked","true");
Copy after login

Related free learning recommendations:javascript(Video)

The above is the detailed content of How to get iframe with jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template