views:

21

answers:

3

hi guys,

i'm working on a little dropdown menu:

<ul>
<li class="section-title">HEADER which triggers dropdown</li>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
</ul>

<ul>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
   <li><a href="element_one">element one</a></li>
</ul>



$('#menu ul').hover(
  function () {  
    $(this).children("li").show('fast');
  },
  function () {
    $(this).children("li").not(':first-child, .active').hide('fast');    
  }
);

i wonder how i can limit the hover function only to ul with a first-child of ".section-title". the hover-function should only fire for ul's with a .section-title.

is that possible?

A: 

$('#menu ul li').eq(0).hasClass('section-title').parent().hover(...);

pritaeas
A: 

try

$('#menu ul').each(function(){
  var  bol = $(this).children('li.section-title') > 0;
  if (bol){
       $(this).hover(
           function () {  
              $(this).children("li").show('fast');
           },
           function () {
              $(this).children("li").not(':first-child, .active').hide('fast');    
           }
       );
  }
});
Reigel
A: 

do it reverse.

$('li.section-title:first-child').parent().hover(function(){
     $(this).children("li").show('fast');
}, function(){
     $(this).children("li").not(':first-child, .active').hide('fast');
});
jAndy
this was was my choice also, but will this still behave as intended if there are many `li` with `class="section-title"` in one parent `ul`?
Reigel
@Reigel: I realized that also, `.is(':first-child')` does not work for some reason.
jAndy
well, it works for the OP! cheers! lol :)
Reigel
@Reigel: well I updated the code, that works well. `.is(':visible')` could not work abviously, it just returns a boolean value.
jAndy