0

all, I`ve a question about get iframe's element by attribute using javascript.

1.html

<iframe id="if" src="2.html">
<div attr="test">

2.html

<div attr="test">

I`ve already known that if parent page want to get the its element by attribute, we can use jQuery like

$("div[attr='test']")

But how can parent get it's iframe's element by attribute?

Please write some simple code for explain, great thanks!

Jarod

I`ve found out a solution and test fine:

$("iframe[data-label='if']").contents().find("div[attr='test']");
1
  • old question, but worth noting that the html is likely malformed or OP is trying to do a DOM lookup in the iframe from the parent window, which is effectively impossible Commented Jan 26, 2014 at 18:35

2 Answers 2

1

If I'm not totally off:

$("iframe div[attr='test']")...

Or with id:

$("#if div[attr='test']")...
Sign up to request clarification or add additional context in comments.

1 Comment

I've another question, if the iframe has no id but only a attribute, how can I do this? 1.html <iframe attr="if" src="2.html"> <div attr="test"> 2.html <div attr="test">
0

Did you tried?

window.frameElement.getAttribute("data-media");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.