I'm trying to find an <h1>
tag within an iframe with an id of f1
.
Simply trying $("#f1").find("h1")
returned an empty set.
So I thought maybe it was because the iframe didn't have jquery in it, so I couldn't use those methods.
So I tried a couple of different things. Without jquery:
var el = document.getElementById;
el.getElementsByTagName("h1");
no luck. Sort of doesn't really make sense either since getElementsByTagName is a method of the document. Though I sort of thought maybe an iframe would be a separate document.
Lastly I tried to add jquery
var el = document.getElementById("f1")
var s = document.createElement("script");
s.src = "http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js";
el.appendChild(s);
which gets jquery appended to the iframe. I can see it in the inspector in the head of the document embedded in the iframe. Yet
var el = document.getElementById("f1");
el.find("h1");
gets the typeError Object #<HTMLIFrameElement> has no method 'find
How can I get the value of my <h1>
tag?