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.
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');
Edit: 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.
Jquery – manipulating classes in a simple dropdown menu