Hello, I'm having a hard time generalizing a dropdown function, I guess I'm doing something wrong, I searched on forums and did not find the answer so I'll open that topic.
My HTML code is like this, there are several buttons with the same classes but I want each one to do a dropdown only for its respective menu:
<a class="sb-dropdown-toggler" href="#" style="border-color: #05204A">
<i class="fas fa-wrench sb-icon-size"></i><i class="fas fa-caret-down">
</i><span>Ferramentas</span>
</a>
<div class="sb-dropdown-menu">
<a href="#">Action</a>
<a href="#">Another action</a>
<a href="#">Something else here</a>
</div>
CSS like this:
.sb-dropdown-menu{
display: none;
}
.sb-dropdown-menu.dropdown-active{
display: block;
}
And JavaScript like this:
$('.sb-dropdown-toggler').each(function () {
$(this).click(function (e){
e.preventDefault();
$(this + ' .sb-dropdown-menu').toggleClass("dropdown-active");
});
});
My intention is to make the submenu of each button activated only by your "parent", can you do it the way I'm doing? Do I have to add or remove something? I tried in several ways and I could not, I imagine that I have to add an ID for each one but I do not know how to do it, I appreciate the help of whoever I can