First of all, let me say that I am a very beginner when it comes to Jquery. I am working from the book Novice to Ninja, and building a vertical multilevel sliding menu. All works fine. I have given the LI elements that i like to have default expanded a classname .active. I'd really like to start the menu with these classnames active/expanden. Is this possible? And how can this be done?
I have attached the code
thanks in advance
greetz,
walter
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Untitled Document</title><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript" charset="utf-8"></script><script type="text/javascript"><!-- menu $(document).ready(function(){ $('#maincontent_menu ul > li ul') .click(function(e){ e.stopPropagation(); }) /*.filter(':not(:first)')*/ .hide(); $('#maincontent_menu ul > li, #maincontent_menu ul > li > ul > li').click(function(){ /* var selfClick = $(this).find('ul:first').is(':visible'); if(!selfClick) { $(this) .parent() .find('> li ul:visible') .slideToggle(); } */ $(this) .find('ul:first') .stop(true, true) .slideToggle(300); }); });//--></script></head><body><div id="maincontent_menu"><ul id="accordion"> <!-- first level --> <li> <a href="page.html" class="active">non expandable</a> </li> <!-- first level --> <li> <a href="page.html">non expandable</a> </li> <!-- first level --> <li> <a href="page.html">non expandable</a> </li> <!-- first level --> <li> <a href="page.html">non expandable</a> </li> <!-- first level --> <li> <a href="page.html">non expandable</a> </li> <!-- first level --> <li> <a href="page.html">non expandable</a> </li> <!-- first level --> <li class="active"> Expandable <ul> <li class="second"> Expandable <ul> <li><a href="pagina.html">non expandable</a></li> </ul> </li> <li class="second"> <span class="active">expandable</span> <ul> <li><a href="pagina.html">non expandable</a></li> <li><a href="pagina.html" class="active">non expandable</a></li> <li><a href="pagina.html">non expandable</a></li> </ul> </li> <li><a href="pagina.html">non expandable</a></li> </ul> </li> </ul> </div></body></html>
If so, inside your $(document).ready(function
$('#ElementID').addClass('
Open in new window