Carlos Perez
Carlos Perez

Reputation: 435

Drop down menu not closing jquery

What I'm trying to do is a drop down menu, and the user click on of the items inside the menu automatically closes the menu, now if working but because I'm using the

  • to closes the menu is causing me a lot problem so I decide to change but it don't work. Heres a demo http://jsfiddle.net/nWxe6/2/

    This is function that works

     $("li").click(function(event)
      {
        $(this).closest("div").hide("slow"); 
    
      });
    

    but this one doesn't

     $("hideM").click(function(event)
      {
        $(this).closest("div").hide("slow"); 
    
      });
    

    Upvotes: 0

    Views: 176

  • Answers (3)

    Kiranramchandran
    Kiranramchandran

    Reputation: 2094

    Change this

    $("hideM").click(function(event)
      {
        $(this).closest("div").hide("slow"); 
    
      });
    

    To

    $("#hideM").click(function(event){
    
        $(this).closest("div").hide("slow"); 
    
      });
    

    If you are using id as your jquery selector , you need to prefix #.

    DEMO HERE

    Upvotes: 2

    Dennis
    Dennis

    Reputation: 125

    You're missing '#'. Currently you are trying to use a HTML element 'hideM', which doesn't exist. To use your element with ID 'hideM', you have to use

    $("#hideM").click(function(event) {
        $(this).closest("div").hide("slow");
    });
    

    Demo

    Upvotes: 1

    Neel
    Neel

    Reputation: 11721

    You need to add "#" as shown below...

    $("#hideM").click(function(event)
      {
        $(this).closest("div").hide("slow"); 
    
      });
    

    Demo :- http://jsfiddle.net/5EQzs/1/

    Upvotes: 1

    Related Questions