var photo=$('div.photo'); photo.click(function(ev) { $(this).toggle(); var next=$(this).next(); next=(next.size() > 0)? next:photo.eq(0); next.toggle(); }); photo.eq(0).nextAll().hide();
<div class="photo"><img src="../../../resources/photo1.jpg" alt="東京駅" /></div> <div class="photo"><img src="../../../resources/photo2.jpg" alt="東京駅" /></div> <div class="photo"><img src="../../../resources/Desktop.jpg" alt="東京駅" /></div> <div class="photo"><img src="../../../resources/lion.jpg" alt="東京駅" /></div>