我想隐藏父 div 并显示父父(同一类)的下一个 div。
<div class="collections">
<div class="switchswitch">
<span>title</span>
<span class="switch middle">
<img class="wp-post-image" src="image.jpg">
</span>
</div>
<div class="switchswitch">
<span>title</span>
<span class="switch middle">
<img class="wp-post-image" src="image.jpg">
</span>
</div>
<div class="switchswitch">
<span>title</span>
<span class="switch middle">
<img class="wp-post-image" src="image.jpg">
</span>
</div>
</div>
...CSS:
.switchswitch {
display: none;
}
.selected{
display: block;
}
...和js:
$('.wp-post-image').click(function(){
var $next = $('.switchswitch').removeClass('selected').parent('.collections').next('.section')
if ($next.length) {
$next.addClass('selected');
}
else {
$(".switchswitch:first").addClass('selected');
}
});
它应该是一个循环,每次我单击“wp-post-image”类的图像时,父 div“switchswitch”应该被隐藏,下一个“switchswitch”应该出现..