Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 471
priyank Avatar asked Jun 24 '11 20:06

priyank


2 Answers

Try:

$("div#test", $("#someIFrame").contents())
like image 152
Matthew Manela Avatar answered Nov 13 '22 07:11

Matthew Manela


yeah I got it. thanks.

This is what I wrote.

$("div[id='test'] > span",frames['frame1'].document).text()
like image 34
priyank Avatar answered Nov 13 '22 08:11

priyank