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

南笙酒味 提交于 2019-11-27 10:50:01
Kristoffer Sall-Storgaard

Use the not selector.

Example:

$('.collapsiblock').click(function(){
     $('.collapsiblock').not(this).each(function(){
         $(this).slideUp();
     });
     $(this).slideDown();
})

Try this,

Example:

$('.collapsiblock').click(function(){
   $('.collapsiblock').not(this).slideUp();
   $(this).slideDown();
});

This is better way because if you use each function so it will load and in future you have more then thousands div so it will take long time to SlideUp or SlideDown.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!