开发者

jquery hover function only for ul with class?

开发者 https://www.devze.com 2023-01-05 20:51 出处:网络
i\'m working on a little dropdown menu: <ul> <li class=\"section-title\">HEADER which triggers dropdown</li>

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="eleme开发者_Python百科nt_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?


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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消