JQuery: Toggle Element that is clicked and hide all other

前端 未结 4 629
别那么骄傲
别那么骄傲 2020-12-02 21:12

I want to hide any visible span elements if any is visible, and toggle it again if a element is clicked


      
4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 21:52

    You can hide all the spans by using a span selector, then using the $(this) keyword to find the span next to the clicked link:

    $(".item a").click(function() {
      // Hide all item spans
      $(".item span").hide();
      // Show the element next to this
      $(this).next().show();
    });
    

提交回复
热议问题