I think I may know the answer to this, but being still fairly new to the world of jQuery I figure I will ask people much smarter than I. My research on the topic led me to the code I have pasted below but it does not work.
Here is the scenario: I have multiple div/ul based dropdowns that have the same class name of course. What I want to happen is when the button for the dropdown is clicked, that you can click inside of the dropdown element without it closing the dropdown. I am assuming that because they all have the same class, the stopPropogation
is not working. Here is the jQuery code:
<script type='text/javascript'>
$('.dropdown-menu').each(function(){
$(this).click(function(event){
if($(this).hasClass('keep_open')){
event.stopPropagation();
}
});
});
</script>
Here is an example of one of the dropdowns (of which there are more than one). I use Twitter Bootstrap in case you notice the similar class names:
<div class="btn-group">
<div class="btn btn-mini" tabindex="-1">DROPDOWN NAME</div>
<div class="btn btn-mini dropdown-toggle" data-toggle="dropdown" tabindex="-1">
<span class="caret"></span>
</div>
<ul class="dropdown-menu dropdown-pad keep-open">
<li><b>Info:</b> <small>NAME INFO</small></li>
<li><b>Thoughts:</b> <small>THOUGHT INFO</small></li>
<li><b>Favorite Places:</b>
<br><small>FAVORITE PLACE<br>FAVORITE PLACE 2</small>
</li>
</ul>
</div>
EDIT So the error is not likely in the jQuery portion, but something in the dropdown div itself. On the same page I use the following variation of the dropdown and it works like a champ:
<div class="btn-toolbar">
<div class="btn-group">
<a class="btn dropdown-toggle" href="#" data-toggle="dropdown">
Department
<span class="caret"></span>
</a>
<ul class="dropdown-menu keep_open">
<li>Customer Service</li>
<li>Tech Support</li>
</ul>
</div>
</div>