jquery – Hide\show div

Question:

I have the Nth number of such elements on the page:

<div class="main">
<a class="text">Любой текст</a>
<div class="buttons">кнопки</div> //этот элемент скрыт по-умолчанию.
</div>

I need that when I click on

<a class="text">Любой текст</a>

Showing div buttons . And only the one that is in this main block.

I found an example script and adjusted it a bit, but the problem is that this opens the buttons of all elements. How to change it?

Link to JSFiddle

Answer:

Another option that definitely works in chrome:

$(".text").click(function() {
     $(this).closest('.main').find('.buttons').show();
});

UPDATE

$(".text").click(function() {
e = $(this).closest('.main').find('.buttons');
    if(!e.is(':visible')) {
    $('.buttons').hide();
    e.show();
}
});

Understood so.

Scroll to Top