横向与横向取代班级 [英] Transversing & replacing classes
问题描述
我希望替换父(li.filetabs
)元素的子元素(ul
)的类名.我所做的事情似乎很正确,但是显然不是,因为该班级没有被取代.
I wish to replace a class name for a child element (ul
) of parent (li.filetabs
) element. What I have done seems quite right but it's obviously not as the class is not being replaced.
使用JSFIDDLE更新 Jsfiddle的注意事项:单击一次即可正常使用,再次单击同一导航选项卡,您会看到下拉菜单消失并重新出现...
UPDATED WITH JSFIDDLE Note for Jsfiddle: when you click once, it all works, click on the same navigation tab again and you see the drop down disappear and reappear...
var aFileTabs = $('.filetabs');
var curTab = $(this);
// this seems to give correct output
var prevCurTab = $('.cTabActive').parent(); //(i.e. *jQuery(li.filetabs)* )
// the following line is the problem line; Ive tried replacing the children with
// $('ul',prevCurTab)... but that doesnt work either... I must be doing something
// very basic wrong
$(prevCurTab).children().removeClass('cTabActive').addClass('cPrevTabActive');
$('ul', curTab).addClass ('cTabActive');
抱歉,我忘记了HTML,还有很多内容,因此仅显示前两个导航按钮html可以理解其含义.
Apologies, I forgot the HTML, there is quite a bit more so only the first two navigation buttons html being shown to get the meaning across.
<div id="filemenu"> <!-- right tabs menu -->
<ul id="fm_ul">
<li class="filetabs">File
<ul>
<li class="m_items"><a href="#"><span class="aHeading">New</span><span class="shortcutK">Ctrl-U</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Open</span><span class="shortcutK">Ctrl-Z</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Save</span><span class="shortcutK">Ctrl-T</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Exit</span><span class="shortcutK">Ctrl-Q</span></a></li>
</ul></li><li class="filetabs">Edit
<ul>
<li class="m_items"><a href="#"><span class="aHeading">Undo</span><span class="shortcutK">Ctrl-M</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Redo</span><span class="shortcutK">Ctrl-S</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Zoom In</span><span class="shortcutK">Ctrl-R</span></a></li>
<li class="m_items"><a href="#"><span class="aHeading">Zoom Out</span><span class="shortcutK">Ctrl-Q</span></a></li>
</ul></li>
推荐答案
在此独立文章中得到了解答.谢谢丹尼尔.
Answered in this separate post. Thanks Daniel.
这篇关于横向与横向取代班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!