April 4, 2012

jQuery – Exclude an li from this function?

Question by CodeyMonkey

I have a ul list of 8 li’s on the last li it has the id #search – I don’t want the dropdown applid to this, how can I exclude it? here’s my code..

$(document).ready(function () {     
  $('#navigation li').hover(function () {
    // Show the sub menu
    $('ul', this).stop(true,true).slideDown(300);
  },
  function () {
  //hide its submenu
   $('ul', this).stop(true,true).slideUp(200);         
  });
});

Thanks

Answer by Starx

Use jQuery’s .not()

$('#navigation li').not("#search").hover(function () {
   // Show the sub menu
   $('ul', this).stop(true,true).slideDown(300);
},
function () {
  //hide its submenu
  $('ul', this).stop(true,true).slideUp(200);         
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!