I'm trying to open a Bootstrap dropdown when I click a item of another dropdown.
The idea is to select a city from the first drop down - then the script will auto open the second dropdown with areas (and show only areas corresponding to the chosen city).
Here is my JS:
$('#sidebar_filter_city li').click(function(){
$('#sidebar_filter_areas').dropdown('toggle');
});
and this is the HTML:
<div class="dropdown form-control">
<div data-toggle="dropdown" id="sidebar_filter_cities" class="sidebar_filter_menu" data-value="jersey-city">Jersey City<span class="caret caret_sidebar"></span></div>
<input type="hidden" name="advanced_city" value="jersey-city">
<ul id="sidebar_filter_city" class="dropdown-menu filter_menu" role="menu" aria-labelledby="sidebar_filter_cities">
<li role="presentation" data-value="">All Cities</li>
<li role="presentation" data-value="jersey-city">Jersey City</li>
<li role="presentation" data-value="london">London</li>
<li role="presentation" data-value="new-york">New York</li>
</ul>
</div>
</div>
<div class="dropdown form-control">
<div data-toggle="dropdown" id="sidebar_filter_areas" class="sidebar_filter_menu">All Areas<span class="caret caret_sidebar"></span> </div>
<input type="hidden" name="advanced_area" value="">
<ul id="sidebar_filter_area" class="dropdown-menu filter_menu" role="menu" aria-labelledby="sidebar_filter_areas">
<li role="presentation" data-value="">All Areas</li>
<li role="presentation" data-value="east-harlem" data-parentcity="">East Harlem</li>
<li role="presentation" data-value="greenville" data-parentcity="">Greenville</li>
<li role="presentation" data-value="manhattan" data-parentcity="">Manhattan</li>
<li role="presentation" data-value="northern-brooklyn" data-parentcity="">Northern Brooklyn</li>
.....
</ul>
</div>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…