1 回答
TA贡献1853条经验 获得超9个赞
你需要点击听众重视.closeInfo和.openInfo,并且随后事件中,需要切换()类其父项内.event。
$('.closeInfo, .openInfo').on('click', function() {
let $closestEvent = $(this).closest('.event');
$closestEvent.find('.eventInfo, .closeInfo, .openInfo' ).toggle();
});
.event {
margin-bottom: 30px;
}
.eventInfo,
.closeInfo {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="event">
<p class="openInfo"><span>+</span>Details</p>
<p class="eventInfo"> Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="closeInfo"><span>x</span>Close</p>
</div>
<div class="event">
<p class="openInfo"><span>+</span>Details</p>
<p class="eventInfo"> Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit.Lorem ipsum dolor sit amet, consectetur adipiscing elit</p>
<p class="closeInfo"><span>x</span>Close</p>
</div>
添加回答
举报