-7

I have a navigation bar and I want to show or hide menu options when you click on the headings.

Semi-code below, but what do I enter into the onclick to hide/show the div?

<a href=link onclick=?>MENU 1</a>
  <div id='menu1'>
    Option 1
    Option 2
    Option 3
    </div>
Lix
  • 47,311
  • 12
  • 103
  • 131
Jamal Lanten
  • 69
  • 1
  • 11
  • 10
    [so] is not a **replacement** for Google. Where exactly are you having problems with this? – Lix Feb 25 '14 at 14:14
  • Same reply could be posted on any question on this site. Google directed me here. It is a question based coding site is it not? – Jamal Lanten Feb 25 '14 at 14:16
  • Google did **not** direct you to ask a new question - this is something that you decided to do. You have not addressed my question though.. Where exactly are you having problems with this? – Lix Feb 25 '14 at 14:17
  • 4
    @JamalLanten yes, but Lix's point is that you could have found this answer by looking around at existing content instead of asking a new beginner-level question – Robert Levy Feb 25 '14 at 14:18
  • 1
    possible duplicate of [Switch/toggle div (jquery)](http://stackoverflow.com/questions/752847/switch-toggle-div-jquery) – Volkan Ulukut Feb 25 '14 at 15:13

1 Answers1

0

You can use:

$('a').click(function(e) {
    e.preventDefault();
    $('#menu1').toggle();
})

Fiddle Demo

Felix
  • 37,892
  • 8
  • 43
  • 55
  • 6
    This is the reason there are so many zero effort question on [so]. I realize that you're just trying to help. But don't you want the OP to at least *try* to help themselves first before posting here? I'm hinting towards the whole "teach a man to fish" story... – Lix Feb 25 '14 at 14:15
  • Be aware that `toggle` has been deprecated since JQuery 1.8, and was removed in 1.9. – ElGavilan Feb 25 '14 at 14:18
  • 1
    @ElGavilan toggle(function...function... is removed but not the function toggle itself http://api.jquery.com/toggle/ – Anton Feb 25 '14 at 14:21
  • I have about 5 headings with sub menus to open, would this work? – Jamal Lanten Feb 25 '14 at 14:23
  • 1
    @JamalLanten No, it's not. You need to provide all relevant HTML markup since current markup is not enough detail – Felix Feb 25 '14 at 14:25