所以我有一个 jquery 风格的手风琴,页面上引用了 jquery ui。我正在从数据库中提取导航信息,html 结构如下所示:
<div id="accordion" class="ui-accordion ui-widget ui-helper-reset" role="tablist">
<li class="sub-item">
<div class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons"
role="tab" id="ui-accordion-accordion-header-0" aria-controls="lvl2" aria-selected="false"
tabindex="0">
<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a href="/Ebusiness/events/upcoming-events">
Upcoming Events</a><span id="arrow"></span></div>
<ul id="lvl2" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom"
style="display: none;" aria-labelledby="ui-accordion-accordion-header-0" role="tabpanel"
aria-expanded="false" aria-hidden="true">
<li class="lvl2"><a href="/upcoming-events/meeting-center">Meeting Center</a></li>
</ul>
</li>
<li class="sub-item">
<div class="ui-accordion-header ui-helper-reset ui-state-default ui-corner-all ui-accordion-icons"
role="tab" id="ui-accordion-accordion-header-1" aria-controls="lvl2" aria-selected="false"
tabindex="-1">
<span class="ui-accordion-header-icon ui-icon ui-icon-triangle-1-e"></span><a href="/Ebusiness/Meetings/MeetingsCalendar">
Calendar of Events</a><span id="arrow"></span></div>
<ul id="lvl2" class="ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom"
style="display: none;" aria-labelledby="ui-accordion-accordion-header-1" role="tabpanel"
aria-expanded="false" aria-hidden="true">
</ul>
</li>
</div>
我的目标是删除标签,或者添加一个类,如果 ul#lvl2 列表中没有子项,我可以将其应用到 dispaly:none 。
这是我正在尝试的 jquery 函数,但似乎没有执行
if ( $('#lvl2:hasChildren') ) {
$("#arrow").addClass("empty"); }
我没有抛出任何错误。
谢谢