Hide particular div onload and then show div after click

前端 未结 6 1103
故里飘歌
故里飘歌 2020-12-14 11:31

I have two divs div1 and div2. I want div2 to be automatically hidden but when i click on preview div then div2 to be mad

6条回答
  •  误落风尘
    2020-12-14 11:46

    Make sure to watch your selectors. You appear to have forgotten the # for div2. Additionally, you can toggle the visibility of many elements at once with .toggle():

    // Short-form of `document.ready`
    $(function(){
        $("#div2").hide();
        $("#preview").on("click", function(){
            $("#div1, #div2").toggle();
        });
    });
    

    Demo: http://jsfiddle.net/dJg8N/

提交回复
热议问题