1
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 blocks .container
, which is already formatted in CSS, I have in each container an element a
that will add a class to the div .option-box
, the problem arises when I click on only one element a
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 get jQuery to manipulate the element of just one .container
?
It worked, thank you very much for your help!
– inodaf
@Isacfadoni added two more options. If your HTML is like in the example they are even better...
– Sergio
I tested the other solutions too, and it worked perfectly. Again thank you very much.
– inodaf