i am trying to create a drop down menu using jQuery.
HTML is:
<div id="cats">
<div id="cat_ram">
<span>RAM</span>
<div class="cat_arrow"></div>
<div class="cat_options">
<ul class="cat_list">
<li>1GB</li>
<li>2GB</li>
<li>3GB</li>
<li>4GB</li>
</ul>
</div>
</div>
</div>
my jQuery code is:
$(document).ready(function(e) {
$('.cat_options').hide();
$('.cat_arrow').click(function(){
$('.cat_options').toggle();
});
$(document).click(function(){
if($('.cat_options').is(':visible')){
$('.cat_options').hide();
}
})
});
Here is what i am trying to accomplish:
1)when .cat_arrow is clicked the drop down menu i.e .cat_options should be shown.And when it is clicked again it should hide.
2)While .cat_options is visible if a click event occurs any where else on the page (not on .cat_arrow) .cat_options should hide.
Now the problem is that:
1)For above code the .cat_options never shows. And if i add another if condition like this
if($('.cat_options').is(':hidden')){
$('.cat_options').show();
Then clicking anywhere in the document would make the .cat_options visible i.e the .cat_arrow would become useless.