javascript - get h1 tag within iframe -


this question has answer here:

i'm trying find <h1> tag within iframe id of f1.

simply trying $("#f1").find("h1") returned empty set.

so thought maybe because iframe didn't have jquery in it, couldn't use methods.

so tried couple of different things. without jquery:

var el = document.getelementbyid; el.getelementsbytagname("h1"); 

no luck. sort of doesn't make sense either since getelementsbytagname method of document. though sort of thought maybe iframe separate document.

lastly tried 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 iframe. can see in inspector in head of document embedded in iframe. yet

var el = document.getelementbyid("f1"); el.find("h1"); 

gets typeerror object #<htmliframeelement> has no method 'find

how can value of <h1> tag?

assuming content of iframe same domain parent window, can use contents():

$("#f1").contents().find("h1"); 

if domains different, you're out of luck same origin policy deny access.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -