如何选择多个给定元素的子元素? [英] How to select multiple elements that are children of given element?
本文介绍了如何选择多个给定元素的子元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有<div id='mydiv'>
,我需要选择所有pre
和div
元素,它们是#mydiv
的子元素.
I have <div id='mydiv'>
and I need to select all pre
and div
elements that are children of #mydiv
.
我可以这样:
div#mydiv > pre, div#mydiv > div
但是,可以做到只引用一次#mydiv
吗?
but, can it be done so that #mydiv
is referenced only once?
div#mydiv > pre, div
将选择页面上的所有div
,无论它们是#mydiv
的子级,因此逗号都不是实现此目的的方法.也许还有另一种我不知道的语法?
will select all div
s on the page regardless if they're children of #mydiv
, so the comma isn't a way to do it. Maybe there's another kind of syntax I don't know about?
推荐答案
您必须两次引用#mydiv
...
You'll have to reference #mydiv
twice...
#mydiv > pre, #mydiv > div
由于ID足够具体,我删除了多余的div
元素选择器.
I removed the extraneous div
element selector as the ID is specific enough.
这篇关于如何选择多个给定元素的子元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文