priyank priyank - 15 days ago 7
jQuery Question

Selector for element inside a frame (with same origin)

I have a webpage with the following structure:

<html>
<head>...</head>
<frameset>
<frame name="frame1" src="/index.jsp"/>
<frame name="frame2" src="/blank.jsp"/>
</frameset>
</html>


index.jsp
contains:

<html>
<head>...</head>
<body>
... <div id="test">test is here</div> ...
</body>
</html>


I need a jQuery selector to directly access
div#test
. So far I've only been able to write it like this:
$(frames[0].document.body)
...or this:
$("frame[name='frame1']")
. But I have a template which requires me to write my selector inside
$("here only")
. So I can't use
.find()
or other functions.

Answer

Try:

$("div#test", $("#someIFrame").contents())
Comments