我要的風格的UL像這樣:的jQuery和.css()的問題
<ul id="accordion">
<li id="block.mainnavigation.cell">
<ul style="display: block; font-weight: bold;">
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEGRND" id="block.mainnavigation.link">Ground Coffee</a>
<ul style="display: block;">
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEGRNDCAFECOLL" id="block.mainnavigation.link" style="font-weight: normal;">Café Collection Coffee</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEGRNDFAIRTRAD" id="block.mainnavigation.link" style="font-weight: normal;">Fair Trade Organic Coffee</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEGRNDOTHER" id="block.mainnavigation.link" style="font-weight: normal;">Ground Coffee Other</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEGRNDPREMCAN" id="block.mainnavigation.link" style="font-weight: normal;">Premium Coffee -Can</a>
</li>
</ul>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEPOD" id="block.mainnavigation.link">Coffee Pods</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEWHLBN" id="block.mainnavigation.link">Whole Bean Coffee</a>
<ul style="display: block;">
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEWHLBNBULK" id="block.mainnavigation.link" style="font-weight: normal;">Whole Bean Coffee Bulk</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEWHLBNCAFECOLL" id="block.mainnavigation.link" style="font-weight: normal;">Café Collection Coffee</a>
</li>
<li id="block.mainnavigation.cell">
<a target="" href="/event/catalog:items/categoryCode/COFFEEWHLBNOTHER" id="block.mainnavigation.link" style="font-weight: normal;">Whole Bean Coffee Other</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>
所以我試圖用這樣的:
$('ul#accordion ul').parent().children(":first").css('font-weight','bold')
我試圖讓嵌套UL的父母,並使其大膽,但我得到的是所有李和他們包含的鏈接變得大膽。
出於某種原因,如果我嘗試設置在底邊框的屬性它按預期工作:
$('ul#accordion ul').parent().children(":first").css('border-bottom','1px solid green')
對我缺少的是什麼在這裏的任何想法,將不勝感激。
雖然沒有解答您最初的問題,選擇$(「#手風琴」)將快於$('UL #手風琴')。我曾經做過同樣的事情。 – MoarCodePlz
你可以發佈'html' – Rafay
你是什麼意思與nexted ul的父母?包含UL的div?因爲那很明顯..如果你設置包含ul的div的font-weight:BOLD,顯然div的子節點(因此ul和它的li)也變得粗體。 – Jules