Selector for element inside a frame (with same origin)

priyank picture priyank · Jun 24, 2011 · Viewed 24.6k times · Source

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

Matthew Manela picture Matthew Manela · Jun 24, 2011

Try:

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