views:

419

answers:

2

I'm looking to create a basic DIV based dropdown menu:

<ul id="menu">
    <li>
        <a href="#">item 1</a>
        <div class="submenu">something here</div>
    </li>
    <li>
        <a href="#">item 2</a>
        <div class="submenu">something else here</div>
    </li>
    <li>
        <a href="#">item 3</a>
        <div class="submenu">something more</div>
    </li>
</ul>

jQuery:

$j('.submenu').hide()
$j("#menu li a").hover(
  function () {
    $(this).addClass('active').next('.submenu').addClass('active').slideDown('fast');
  }, 
  function () {
    $(this).addClass('active').next('.submenu').addClass('active').slideUp('fast');
  }
);

... isn't working.

+2  A: 
"#menu ul li a"

references nothing. menu is a ul

dbrien
Oh sorry about that, nesting is not the problem in my case, I've verified it.
Nimbuz
I just ran a simple test after removing ul and it worked. I also changed $j to just $, but I'm not sure if you are using some kind of alias there. I also added a semicolon after hide() and changed the quotes to double quotes in ".submenu"
dbrien
A: 

ul is not beneath #menu, it is #menu, try this:

$j(document).ready(function(){
  $j('.submenu').hide();
  $j("#menu li a").hover(
    function () {
      $(this).addClass('active').next('.submenu').addClass('active').slideDown('fast');
    }, 
    function () {
      $(this).removeClass('active').next('.submenu').removeClass('active').slideUp('fast');
    }
  );
});
Nick Craver