V
V
Vladimir Mazepa2015-10-29 15:49:19
JavaScript
Vladimir Mazepa, 2015-10-29 15:49:19

How to collapse a list after selecting an item in it?

Hello!
There is a list of divs, you need to collapse it when selecting / clicking on any position from the list.

<div id="markerlist">
<div><a href="#" class="title">ул. 23-го Августа, 43</a></div>
<div><a href="#" class="title">ул. Академика Павлова, 305/307</a></div>
<div><a href="#" class="title">ул. Энвера Ахсарова, 21</a></div>
<div><a href="#" class="title">ул. Блюхера, 18б</a></div>
<div><a href="#" class="title">ул. Блюхера, 23е</a></div>
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
petyagrill, 2015-10-29
@petyagrill

Something like this

$("#markerlist").on("click","div", function(){
  $('#markerlist div').hide();
    $(this).show(); 
    return false;
});

M
Mikhail, 2015-10-29
Chirskiy @chirskiy_mixail

Could it be even easier? )

$("#markerlist").on("click","div", function(){
    $(this).show().siblings().hide(); 
    return false;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question