Change DIV contents using jQuery when link clicked

后端 未结 6 1560
梦毁少年i
梦毁少年i 2021-01-26 02:15

Thank you, in advance, for those who answer =)
I\'m trying to switch between divs when i click the links with the respective class (as follow on the code bellow). It works f

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 02:52

    I think that the best way to fix it is this:

    HTML:

    
      

    Info

    Info content ...

    jQUERY:

    $(document).ready(function(){
    $(".content").hide();
    
    $(".cont").click(function() {
    if ($(this).hasClass("info")){ $("#info").slideToggle(500); }
    if ($(this).hasClass("gallery")){ $("#gallery").slideToggle(500); }
    if ($(this).hasClass("projectos")){ $("#projectos").slideToggle(500); }
    if ($(this).hasClass("contactos")){ $("#contactos").slideToggle(500); }
        // $(".content").slideToggle(500);
    });
    });
    

    All I've done was to change cont id to cont class. Remember that two or more elements can't have the same ID, so only the first element will be considered.

    Ah! And as lmsteffan told, in JQUERY you're using "galerias" and in HTML "gallery". Please check it.

提交回复
热议问题