Encountering a common issue, I am having difficulty adapting existing solutions to my unique situation. I am working with a jquery vertical accordion menu intended for navigation across two websites: home.html and research.html. Below is the relevant excerpt from my home.html:
<div id="cssmenu">
<ul>
<li class='active'><a href='index.html'>Home</a></li>
<li><a href='research.html'>Research</a>
<ul>
<li><a href='research.html#r1'><span>interests</span></a></li>
<li><a href='research.html#r2'><span>preprints</span></a></li>
<li><a href='research.html#r3'><span>publications</span></a></li>
<li><a href='research.html#r4'><span>coauthors</span></a></li>
</ul>
</li>
</ul>
Here's how the relevant portion of my research.html file appears:
<div id="cssmenu">
<ul>
<li><a href='index.html'>Home</a></li>
<li class='active'><a href='research.html'>Research</a>
<ul>
<li><a href='research.html#r1'><span>interests</span></a></li>
<li><a href='research.html#r2'><span>preprints</span></a></li>
<li><a href='research.html#r3'><span>publications</span></a></li>
<li><a href='research.html#r4'><span>coauthors</span></a></li>
</ul>
</li>
</ul>
Additionally, here is the jQuery code snippet in question:
$(document).ready(function(){
$('#cssmenu > ul > li ul').each(function(index, e){
var count = $(e).find('li').length;
var content = '<span class="cnt">' + '</span>';
$(e).closest('li').children('a').append(content);
});
$('#cssmenu > ul > li > a').click(function() {
$('#cssmenu li').removeClass('active');
$(this).closest('li').addClass('active');
var checkElement = $(this).next();
if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
$('#cssmenu ul ul:visible').slideUp('normal');
checkElement.slideDown('normal');
}
if($(this).closest('li').find('ul').children().length == 0) {
return true;
} else {
return false;
}
});
Upon clicking 'Research,' the sub-menu expands as expected. However, selecting a sub-menu entry results in the previously opened sub-menu closing. How can this behavior be prevented? Your assistance would be greatly appreciated, taking into account my limited web programming knowledge.