I recently created this HTML document:
<div class="wrap">
<div class="container">
<a class="button" href="#" title="Abrir as opções."></a>
<div class="option-box">
<ul>
<li><a href="#">Ação 1</a></li>
<li><a href="#">Ação 2</a></li>
<li><a href="#">Ação 3</a></li>
<li><a href="#">Ação 4</a></li>
</ul>
</div>
</div>
<div class="container">
<a class="button" href="#" title="Abrir as opções."></a>
<div class="option-box">
<ul>
<li><a href="#">Ação 1</a></li>
<li><a href="#">Ação 2</a></li>
<li><a href="#">Ação 3</a></li>
<li><a href="#">Ação 4</a></li>
</ul>
</div>
</div>
I have two .container
blocks, which is already formatted in CSS, I have in each container a a
element that will add a class to the .option-box
div, the problem arises when I click on only a a
element and jQuery adds the classes to the .option-box
of the other .container
, causing two menus to appear.
Javascripts below:
$(function optionbox() {
var box = $('.container .option-box');
var button = $('.container a.button');
button.on('click', function optionbox(){
box.toggleClass('show');
});
});
How to make jQuery handle the element of only a .container
?