简体   繁体   中英

How to close a div on second click?

I can't close the div on second click on mobile version, when I click on it for the 2nd time it re-opens, I can just close if I click on another div but that div opens so I have to reload the page to close the divs... JAVASCRIPT:

$(document).ready(function () {
$(window).on("resize", function (e) {
    checkScreenSize();
});

checkScreenSize();

function checkScreenSize() {
    var newWindowWidth = $(window).width();
    if (newWindowWidth < 768) {
        $(document).ready(function () {
            $('.hero-overlay-block-1').click(function () {
                $('.block-uzo').slideToggle("slow");
                $('block-uzo').css('display', 'block');;
                $('.block-more-1').hide();
                $('.block-misija').hide();
                $('.block-vizija').hide();
            });
        });
        $(document).ready(function () {
            $('.hero-overlay-block-2').click(function () {
                $('.block-misija').toggle("slow");
                $('.block-misija').css('display', 'block');;
                $('.block-more-2').hide();
                $('.block-uzo').hide();
                $('.block-vizija').hide();
            });
        });
        $(document).ready(function () {
            $('.hero-overlay-block-3').click(function () {
                $('.block-vizija').toggle("slow");
                $('block-vizija').css('display', 'block');;
                $('.block-more-3').hide();
                $('.block-uzo').hide();
                $('.block-misija').hide();
            });
        });
    }
}

});

<script>
    $(document).ready(function(){
    $(".desc_div").slideUp();

    $(".open_div").click(function(){
        if($(this).hasClass('selected')){
           $(this).removeClass('selected'); 
             $(this).addClass("selected").next(".desc_div").slideUp("slow", function() {
            $(this).prev().removeClass('selected');

        }); 
        }
        else{               $(this).addClass("selected").next(".desc_div").slideDown("slow");
            }
    });
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM