I have created a custom navigation bar called ''Services'' and I want to add a drop down menu on it with jQuery I have this code.
HTML
CSS
jQuery for the drop down menu
HTML
- Code:
<div id="nav">
<a class="dropdown-toggle" href="#">Menu</a>
<ul class="dropdown">
<li><a href="#">Menu Item 1</a></li>
<li><a href="#">Menu Item 2</a></li>
<li><a href="#">Menu Item 3</a></li>
<li><a href="#">Menu Item 4</a></li>
</ul>
</div>
CSS
- Code:
div#nav {
position: relative;
}
div#nav a {
padding: 5px 15px 5px;
}
.dropdown-toggle {
padding: 0;
background: #777;
}
ul.dropdown {
display: none;
position: absolute;
top: 100%;
margin-top: 5px;
padding: 5px 5px 0 0;
background: #777;
}
ul.dropdown li {
list-style-type: none;
}
ul.dropdown li a {
text-decoration: none;
padding: 0em 1em; display:
block;
}
jQuery for the drop down menu
- Code:
$(function() { // Dropdown toggle
$('.dropdown-toggle').click(function() { $(this).next('.dropdown').slideToggle();
});
$(document).click(function(e)
{
var target = e.target;
if (!$(target).is('.dropdown-toggle') && !$(target).parents().is('.dropdown-toggle'))
//{ $('.dropdown').hide(); }
{ $('.dropdown').slideUp(); }
});
});
Last edited by Mati on October 10th 2023, 4:50 pm; edited 1 time in total