我需要做的是在单击 .info 时切换 .information ,同时隐藏所有其他 .information div。我目前可以这样做我的问题是当我单击关闭打开的 .information div 时它不会关闭。如何修改以下代码来做到这一点?我有一个 toggle() 所以认为它会起作用?只是掌握jQuery!
<ol id="resonsToCome">
<li>
<p>A packed and extensive activites programe</p>
<div class="info">
<img src="images/icons/information.png" width="24" height="24" />
</div>
<div class="information">
<p>The 40+ activities range from 1 to 2 hours. As everything is on site there is no time wasted travelling which ensures up to 5/6 activities per day.</p>
</div>
</li>
<li>
<p>Instructors stay with their group throughout your stay</p>
<div class="info">
<img src="images/icons/information.png" width="24" height="24" />
</div>
<div class="information">
<p>Building a trust and friendship with our customers makes your stay memorable in so many ways.</p>
</div>
</li>
<li>
<p>Friendly and experienced instructors</p>
<div class="info">
<img src="images/icons/information.png" width="24" height="24" />
</div>
<div class="information">
<p>Our instructors take part in a rigorous selection and continuous training programme.</p>
</div>
</li>
<li>
<p>A great environment and perfect location!</p>
<div class="info">
<img src="images/icons/information.png" width="24" height="24" />
</div>
<div class="information">
<p>25 acres of beautiful Somerset fields, woodlands and river only 2 hours from London and 1 hour south of Bristol and Bath.</p>
</div>
</li>
</ol>
和 jQuery
$('div.info').on('click', function() {
$('.information').hide();
$(this).closest('ol#resonsToCome li').find('.information').toggle();
});