[英]Select a body within a div with jQuery
I have an element (for example, a body) nested somewhere inside a div.. Something like: 我有一个元素(例如,一个正文)嵌套在div内的某个地方..类似于:
<div class=wrapper>
..
..
<body>
</body>
</div>
How would I go about selecting the body with jQuery? 我如何选择jQuery选择身体?
As others have said - this doesn't look like valid HTML - I'm going to assume that you just gave that as an example as this technique can be used to find any type of element.
正如其他人所说 - 这看起来不像有效的HTML - 我会假设您只是将其作为示例,因为此技术可用于查找任何类型的元素。
This should do the trick to locate the body tag - 这应该可以找到身体标签 -
$('div.wrapper').find('body')
When you don't specify in your selector that you are talking about a class .
当你没有在你的选择器中指定你正在谈论一个类
.
or id #
attribute - the whole string will be matched to the type of element. 或id
#
属性 - 整个字符串将匹配元素的类型。
The same could be done for - 同样可以做 -
<img>
tags - <img>
标签 - $('div.wrapper').find('img')
<a>
tags - <a>
标签 - $('div.wrapper').find('a')
<span>
tags - <span>
标签 - $('div.wrapper').find('span')
Your HTML Markup is off, first of all. 首先,您的HTML标记已关闭。
<body>
<div class="wrapper">
<div class="body">
..
..
</div>
</div>
</body>
Select it with $('div.wrapper div.body')
用
$('div.wrapper div.body')
选择它
Thanks to ClarkeyBoy for pointing out my mistakes, fixed my post. 感谢ClarkeyBoy指出我的错误,修复了我的帖子。
它看起来不像有效的HTML,但试试这个:
$('div.wrapper body')
Surely that HTML isn't correct to have a body tag within a div? 当然,在div中有一个body标签,HTML是不正确的? Unless it's inside an iframe?
除非它在iframe里面?
However you could use this to select the body tag... 但是你可以使用它来选择body标签......
jQuery("div.wrapper body").whatever();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.