Saturday, October 2, 2010

JQuery menu anchor tag click problem

Hi All,

Once again a new problem with another solution. If you have ever tried to create a JQuery menu whose click pops out another sub menu and you have to place an anchor tag with in that submenu, you wont find the anchor tag click to be working.

Suppose i have the following structure.

<div class="menu">
        <li><a href="#">My Parent Menu</a>
            <li><a href="myPage.aspx">My Title</a></li>
            <li><a href="#">another Title</a></li>

and you need the internal UL to pop out on clicking external LI. The JQuery sample is.

$('.menu ul li').click(function () {
  submenu = $(this).find('ul');
  if (':visible'))
  return false;

So what you need to do is to stop propagation of external li item to the anchor tag by

$('.menu li ul li a').click(function(e) {

An now you can do your click and pop Ins/pop outs at the same time.

Happy Coding.

No comments: