I do a self-made spoiler tabs which have a link.
I need a code that will open it when I click on a block, but I cannot open an open one, and if there are no problems with this, then I cannot think of how to handle a click on an already active element. normally closes 1 time, but the next time you open it, the activity class is no longer hanging.
Here is the code for the slider itself:
<div class="spoiler"> <div class="item"><div class="item-title">№201</div> <div class="detail">Lorem ipsum</div> </div> <div class="item"><div class="item-title">№202</div> <div class="detail">ipsum dolor</div> </div> <div class="item"><div class="item-title">№203</div> <div class="detail">dolor sit</div> </div> </div> from classes everything is clear, here is js:
$('.spoiler .detail').hide(); $('.spoiler .item-title').click(function(){ a=0; $('.item.active').removeClass("active"); $(this).parent().addClass("active"); if(typeof $prev != "undefined"){ if($previ != $(this)[0]){ $prev.slideUp(); }else{ a=1; $(this).parent().removeClass("active"); } } if(a==1){ $(this).next().slideToggle(); }else{ $(this).next().slideDown(); } $prev = $(this).next(); $previ = $(this)[0]; }); I tried to close all the blocks first and then work with the pressed one and remember the pressed block to work with it the next time I press it, but I don’t know how to win this problem, everything works except for handling the same block pressing (only with the activity class the problem that changes the style, the block itself unfolds as it should)