how to select all class except the clicked element in JQuery?

前端 未结 3 2103
無奈伤痛
無奈伤痛 2020-12-02 07:46

I have a website developed on Drupal. I use a module called collapsiblock (it is basicly a JQuery plugin) to achieve accordion like effect. It is working fine with me (altho

相关标签:
3条回答
  • 2020-12-02 08:19

    Try this,This is a better way because if you use each function it will load and in the future when you have more than a thousand div it will take a long time to slide up and slide down.

    Example:

    $('.collapsiblock').click(function(){
       $('.collapsiblock').not(this).slideUp();
       $(this).slideDown();
    });
    
    0 讨论(0)
  • 2020-12-02 08:23

    You could keep track of which element has already been clicked with your own jquery click handler and jquery's data(...) function. Then filter iterating your .collapsiblock items with jquery's filter (...) function to include the items you need.

    0 讨论(0)
  • 2020-12-02 08:27

    Use the not selector.

    Example:

    $('.collapsiblock').click(function(){
         $('.collapsiblock').not(this).each(function(){
             $(this).slideUp();
         });
         $(this).slideDown();
    })
    
    0 讨论(0)
提交回复
热议问题