tags:

views:

87

answers:

1

I want to make a dropdown menu for my website with jquery... a couple of problems occur:

  1. The wildcard doesnt seem to work
  2. It won't select it's children with ul.

HTML:

<li class="px6RANDOM">
    <a href="LINK">
        <span>Disclosure</span>
    </a>
 <ul class="subMenu">
       <li>1</li>
          <li>2</li>
          <li>3</li>
 </ul>
</li>

JQuery:

$(function(){
 $("li.px\\S*").children("ul").hide();

 function show() 
 {
  $(this).children("ul").show();
 }
 function hide() 
 {
   $(this).children("ul").hide();
 }

 $("li.px\\S*").hoverIntent({
  sensitivity: 1, 
  interval: 50,   
  over: show,     
  timeout: 1000,  
  out: hide
 });

});

What am I doing wrong? The selector seems to be in order and the children function as well!

I'm a jquery/javascript newbie but want to learn. Please help!


+1  A: 

Try this:

$("li[class^='px']")

As for show and hide: even when the selectors will work, this isn't defined as you expect. Try adding it as an argument for the functions, or remove the functions and inline the code.

Kobi
Ah, me bad..... Is there a good definition somewhere on how the scope of this is explained?
Rickjaah
Well, that depends. jQuery is doing an effort to make sure `this` is right when we expect it, but there's no guarantee the plugin you're using does the same (probably does, though). `this` is a JavaScript feature (not just jQuery), and can be used in many ways.
Kobi