这是我的HTML:
<div id="content">
<img src="myimg.png" alt="this image need to select"/>
<div class="some">
<img src="another.png" alt="this is not need to select"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想选择所有图像它们内部ID content而不是它是内部的div或span的contentDIV即直接选择中的所有图像contentDIV,而不是其内部的的那些div或span内容股利.
有什么想法吗?
您可以使用>这样选择div的直接/直接子项:
#content > img{
// target direct children
}
Run Code Online (Sandbox Code Playgroud)
更多信息: