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.

1
  • 1
    You probably want a semi-colon after this: $j('.submenu').hide(); and the $j, is jquery referenced as such, or as the $ as on the $(this)? Commented Mar 2, 2010 at 18:04

2 Answers 2

3
"#menu ul li a"

references nothing. menu is a ul

Sign up to request clarification or add additional context in comments.

2 Comments

Oh sorry about that, nesting is not the problem in my case, I've verified it.
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"
0

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');
    }
  );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.