JQuery find () - exclude element $ (this)

Basically, I try to find and then start the effect, but I want to exclude the owner element. This is what I have at the moment:

$('li.main').click(function(){ $(this).parents('.content').find('li.main').not(this).removeClass('active'); $(this).parents('.content').find('li.subs').not(this).slideUp(); $(this).parent().toggleClass('active'); $(this).parent().next('li.subs').slideToggle(); }); 

Does not work. Does anyone know how to do this?

+4
source share
1 answer

Try the following:

 $('li.main').click(function(){ var item = $(this), allItems = item.parents('.content').find('li.main'); if(!item.hasClass('active')){ allItems = allItems.not(item); item.parent().addClass('active'); item.parent().next('li.subs').slideDown(); } allItems.removeClass('active'); allItems.slideUp(); }); 
0
source

Source: https://habr.com/ru/post/1444872/


All Articles