I’m creating a drop down menu that will be reused many times on a single page.
The following code works great when there’s only one drop down menu. But when there are multiple drop downs, clicking a single .dropdown will result in all the .dd_menu‘s on the page being revealed.
JS:
$(document).ready(function() {
$('.dropdown').click(function(){
$('.dd_menu').toggle();
});
});
HTML:
<div class="dropdown">
<a class="mini_button" href="#">Actions</a>
<div class="dd_menu">
<a href="http://example.com">Link</a>
<a href="http://example.com">Link</a>
<a href="http://example.com">Link</a>
</div>
</div>
Is there some what to target only the .dd_menu that is inside the particular .downdown which was clicked?
Limit the selector to the
.dd_menuthat is a child of the current clicked.dropdowndiv:jQuery( selector [, context] ):selectorA string containing a selector expressioncontextA DOM Element, Document, or jQuery to use as contextdocs
You can also use the
findfunction:$(this).find('.dd_menu')but it exactly the same. the context selector is calling thefindfunction.