Close Menu with SlideToggle

2

Hello everyone, I have a menu for mobile "hamburger" and I want it to close when I press some menu link.

Menu HTML code:

<div class="menu">
    <button class="hamburger">
        <img src="images/responsive/cel_retrato/ham.png"/>
    </button>
    <button class="cross">&#735;</button>
    <ul clas="menuMM">
        <a href="#topo"><li>HOME</li></a>
        <a href="#pixel"><li>SOBRE</li></a>
        <a href="#servicos"><li>SERVIÇOS</li></a>
        <a href="#projetos"><li>PORTFÓLIO</li></a>
        <a href="#contactM"><li>CONTATO</li></a>
    </ul>
</div>

JavaScript code:

$( ".cross" ).hide();
$( ".menu" ).hide();
$( ".hamburger" ).click(function() {
    $( ".menu" ).slideToggle( "slow", function() {
        $( ".hamburger" ).hide();
        $( ".cross" ).show();
    });
});
$( ".cross" ).click(function() {
    $( ".menu" ).slideToggle( "slow", function() {
        $( ".cross" ).hide();
        $( ".hamburger" ).show();
    });
});

To close the menu I am using this logic, but it is not working.

$( ".menuMM" ).click(function() {
    $( ".menu" ).slideToggle( "slow", function() {
        $( ".cross" ).hide();
        $( ".hamburger" ).show();
    });
});
    
asked by anonymous 20.11.2015 / 18:26

1 answer

1

Correct the attribute clas="menuMM" to class="menuMM" , this is probably causing the error. I made an example in the jsfiddle and it worked perfectly.

    
20.11.2015 / 19:19