简体   繁体   中英

How to access iframe dom element in jquery

I have two jsp pages and js files

one.jsp
two.jsp
one.js
two.js

one.js included in one.jsp, two.js included in two.jsp

two.jsp is loaded by iframe and inherited into one.jsp

My question is

I need to access one.jsp dom elements from two.js(One.js belongs to two.jsp(Iframe))

I tried this. but not working

var parentBody = window.parent.document.body
  console.log(parentBody.find("#tab1").html());

I tried this also from two.js

var x = window.parent.document.querySelector(".nav-tabs li:nth-child("+(numIframe+1)+")");
  x.parentNode.removeChild(x)

It is passing

Uncaught TypeError: Cannot read property 'removeChild' of null

find is not a DOM method. It is a jQuery method.

You either need to use jQuery or use standard DOM.

console.log(window.parent.document.querySelector('#tab1').innerHTML)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM