The following is basic working DropDown menu, child’s appear on parent hover.
<script type="text/javascript">
$(document).ready(function () {
$('#nav li').hover(
function () {
//show its submenu
$('ul', this).stop().slideDown(100);
},
function () {
//hide its submenu
$('ul', this).stop().slideUp(100);
}
);
});
</script>
<style type="text/css">
#nav li {background-color:#CCC; }
</style>
<ul id="nav">
<li><a href="#" class="selected">Parent A</a>
<ul>
<li><a href="#">Item a1</a></li>
<li><a href="#" class="selected">Item a2</a></li>
<li><a href="#">Item a3</a></li>
</ul>
</li>
<li><a href="#">Parent B</a>
<ul>
<li><a href="#">Item b1</a></li>
<li><a href="#">Item b2</a></li>
<li><a href="#">Item b3</a></li>
<li><a href="#">Item b4</a></li>
</ul>
</li>
</ul>
Currently child’s appears when hover is anywhere on the area of the parent box (i.e. also outside the text, on the invisible area of the parent div).
I want the child’s to appear only on hover of the parent link (on the ‘href’ text only).
I couldn’t find the answer anywhere.
Try using the
aelement as target forhoverinstead of the entireli, as follows:See working demo .