So, I've been having problems getting my JavaScript to keep a element's class changed. Whenever I try and change the element's class to "overlist" it works for less than a second, and then reverts it right back to it's original state, underlist. I cannot figure out a way to make it so the class stays.
HTML:
<ul class="overlist">
<li>
<a onClick="activateTutorials()">Tutorials</a>
<ul class="underlist Tutorials">
<li>
<a href="#" onClick="frame(1)">Filler Text</a>
</li>
<li>
<a href="#" onClick="frame(2)">More Filler Text</a>
</li>
<li>
<a href="#" onClick="frame(3)">Foo Tutorial</a>
</li>
<li>
<a href="#" onClick="frame(4)">More foo Tutorial</a>
</li>
<li>
<a href="#" onClick="frame(5)">Foo Guide</a>
</li>
</ul>
</li>
CSS:
.underlist {
display: none;
}
Javascript:
function activateTutorials(){
if(document.getElementsByClassName('Tutorials').classList.contains('underlist')){
document.getElementsByClassName('Tutorials').classList.remove('underlist');
}else{
document.getElementsByClassName('Tutorials').classList.add('underlist');
}
};
underlisttooverlistunder any circumstances.athe id 'underlistToggle')$("a#underlistToggle").click(function() { $(".Tutorials").toggleClass("underlist"); });Example jsFiddle. Just a suggestion and personal opinion--again, I know there are any number of reasons you might not want to use jQuery.