Suffii
Suffii

Reputation: 5784

jQuery issue on prevent Click event on sub list

Can you please take a look at this demo and let me know how I can stop sliding on clicks on sub list of Two and Three. As you can see the jQuery is functioning fine on clicks on parent list but when user clicks on childes still sliding the list which must not. Can you please let me know how I can stop this?

 $(".parent").click(function (e) {
     e.preventDefault();
     $(".musthidden").slideUp();
     $(this).each(function () {
         if ($('.musthidden', this).css('display') == 'none') {
             $(".musthidden", this).slideDown();
         }
     });
 });

Upvotes: 0

Views: 106

Answers (1)

kei
kei

Reputation: 20521

DEMO

 $(".parent > a").click(function (e) {
     e.preventDefault();
     $(".musthidden").slideUp();
     $(this).parent(".parent").each(function () {
         if ($('.musthidden', this).css('display') == 'none') {
             $(".musthidden", this).slideDown();
         }
     });
 });

Upvotes: 1

Related Questions