Search code examples
javascriptjquerycsstoggletoggleclass

Change (toggle) css when clicked on another div


When I click on a div with the classname 'show', i'm adding css to the div 'mobile-menu', this works perfect, but I would like to change the css to another height when I click on the the classname "show" again

$(".show").click(function() { 
$('#mobile-menu').css({ 'height': '100%' });
// when i click on .show again: .css({ 'height': '51px' });
});

Solution

  • Try this code.

    $(".show").click(function() { 
        if ($('#mobile-menu').css('height') === '100%')
            $('#mobile-menu').css({ 'height': '51px' });
        else
            $('#mobile-menu').css({ 'height': '100%' });
    });