本文介紹了如何選擇作為給定元素的子元素的多個(gè)元素?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有 <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
將選擇頁(yè)面上的所有 div
,無(wú)論它們是否是 #mydiv
的子級(jí),因此逗號(hào)不是一種方法.也許還有另一種我不知道的語(yǔ)法?
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
我刪除了無(wú)關(guān)的 div
元素選擇器,因?yàn)?ID 足夠具體.
I removed the extraneous div
element selector as the ID is specific enough.
這篇關(guān)于如何選擇作為給定元素的子元素的多個(gè)元素?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!