我有各种各样的元素.folder
当我单击一个时,我想将类添加active
到其中并从任何其他元素中删除该类。
问题是首先从其他类中删除该类,它根本不这样做。
这是我正在尝试的:
$('.folder').click(function() {
$(this).siblings('.folder').removeClass('active'); // remove from all other <SPAN>s
$(this).addClass('active'); // add onto current
})
示例 HTML:
<ul>
<li class="closed last">
<span class="folder" id="16">More coding</span>
</li>
</ul>
</li>
<li class="closed collapsable lastCollapsable">
<span class="folder active" id="12">Music</span>
<ul style="display: block;" id="browser" class="filetree treeview-famfamfam">
<li class="closed collapsable">
<span class="folder active" id="13">Music child</span>
<ul style="display: block;" id="browser" class="filetree treeview-famfamfam">
<li class="closed last">
<span class="folder" id="15">More music</span>
</li>
</ul>
</li>
<li class="closed last"><span class="folder" id="17">Another child here</span> </li>
</ul>
</li>
</ul>