Completed

jquery menu - improve code to allow to close

I have some jquery code for an accordion type menu. When a main heading (.menubar) is clicked it closes that one and opens the NEXT (.menubar) in the menu. This is what I want, but I also want it modified so if the same menu is clicked again, it will close that menu that was just clicked. Currently it only closes a menu, when a new one is clicked.

Here is the code that works, but needs to be modified to accommodate that change

$(function(){

$('.menubar').click(function(e){

[url removed, login to view]();

$(".submenu").hide();

$(this).next(".submenu").toggle();

return false;

});

$('.subhead').click(function(e){

[url removed, login to view]();

$(this).next(".submenu").toggle();

return false;

});

});

Here is the html. It of course has a link to jquery in the <head> tags.


<div id="menubox">
<div class="menubar" title="This is my title">
MAIN HEADING 1</div>
<div class="submenu">
<li> <a href="first.php" class="loadlink"><div>First Option</div></a> </li>
<li> <a href="second.php" class="loadlink"><div>Second Option</div></a> </li>
<li> <a href="third.php" class="loadlink"><div>Third Option</div></a> </li>
</div>
<div class="menubar" title="This is my title">
MAIN HEADING 2</div>
<div class="submenu">
<li> <a href="first.php" class="loadlink"><div>First Option</div></a> </li>
<li> <a href="second.php" class="loadlink"><div>Second Option</div></a> </li>
<li> <a href="third.php" class="loadlink"><div>Third Option</div></a> </li>
</div>
<div class="menubar" title="This is my title">
MAIN HEADING 3</div>
<div class="submenu">
<li> <a href="first.php" class="loadlink"><div>First Option</div></a> </li>
<li> <a href="second.php" class="loadlink"><div>Second Option</div></a> </li>
<li> <a href="third.php" class="loadlink"><div>Third Option</div></a> </li>
</div>
</div>

Skills: AJAX, Javascript, jQuery / Prototype

See more: code that, type code, jquery c, jquery toggle click, jquery menubar, menu code, code function, hide javascript hide, ajax return, jquery click toggle, javascript toggle, accordion menu accordion menu ajax, hide code, ajax code, accordion menu click, menu function, allow, jquery toggle, ajax submenu code, ajax submenu, javascript ajax jquery, improve code, menu accordion javascript, menu jquery accordion, javascript code hide

About the Employer:
( 13 reviews ) Melbourne, Australia

Project ID: #1128441

Awarded to:

maleo

Hi Sir, Ready to work on this.

$30 AUD in 0 days
(65 Reviews)
5.5

4 freelancers are bidding on average $45 for this job

jqMike

Can fix it quickly and professionally. Please contact me.

$70 AUD in 0 days
(53 Reviews)
6.7
tonykim100

Hello sir! Please check PMB.

$50 AUD in 0 days
(40 Reviews)
5.3
itresumesha

i can do it. lets start now

$50 AUD in 0 days
(1 Review)
0.0
amip1987

I can do that

$50 AUD in 1 day
(0 Reviews)
0.0