简体   繁体   中英

Click link and Show Div then Hide the previous Div

Please help me, i'm having a hard time with this one. I already search for this one on google and here in stackoverflow but I wasn't able to find the specific answer to this one. I hope you can help me. Thanks!

Here's my code:

    $(document).ready(function() {
      $(".link").click(function() {    
        $(".hide").hide();
        var dataType = $(this).attr('data-type');
        $("#" + dataType).show();
    });
});

The previous div is still showing. :( I want to hide it once clicked the link and scroll down to the specific div within the page. :(

Since you didn't specify what your exact expectation, this one would help i guess

 $("div").hide(); // Show chosen div, and hide all others $("a").click(function (e) { //e.preventDefault(); $("#" + $(this).attr("class")).show().siblings('div').hide(); });
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <body> Click to make it visible:<br /><br /> <a href="#" class="one">One</a> <a href="#" class="two">Two</a> <a href="#" class="three">Three</a> <a href="#" class="four">Four</a><br /><br /> <div id="one">One</div> <div id="two">Two</div> <div id="three">Three</div> <div id="four">Four</div><br/><br/> </body>

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