[英]How to select an element across inner <HTML> tag contained in a Iframe with jQuery selector?
I have a weird page with a HTML tag inside another HTML tag, (I know... but it's beyond my control), I try to select the element inside the inner one with jQuery but no luck. 我有一个奇怪的页面,在另一个HTML标记内有一个HTML标记,(我知道...但是这超出了我的控制范围),我尝试使用jQuery选择内部元素中的元素,但是没有运气。 Seems like jQuery won't go across second HTML tag? 好像jQuery不会跨第二HTML标记吗?
For example 例如
<HTML>
<Body>
<div id="foo">
<iframe>
<HTML>
<Body>
<div>
^^^^ select this div ^^^^
</div>
</Body>
</HTML>
</iframe>
</div>
</Body>
</HTML>
I could not select the div (with bar in it) with 我无法选择带有
$('#foo>iframe>HTML>Body>div')
Any input will be greatly appreciated! 任何输入将不胜感激!
Thanks 谢谢
Ok the question was updated, so my previous answer was invalid. 好的,问题已更新,所以我之前的答案无效。
First - Sort out your HTML markup, it is invalid. 首先-整理您的HTML标记,该标记无效。 This is the correct structure for the HTML: 这是HTML的正确结构:
<body>
<div id="foo">
<div>
<p> bar </p>
</div>
</div>
</body>
The jquery to select the div with "bar" inside it is: 选择内部带有“ bar”的div的jquery是:
$('#foo > div > p ').html(); // Returns "bar"
Check this JSFiddle for more info & example: JSFiddle : http://jsfiddle.net/nnysu/ 检查此JSFiddle以获取更多信息和示例:JSFiddle : http : //jsfiddle.net/nnysu/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.