-1

I have a ul list with 3 lis inside it. these lis are buttons to alter the margin of the ul in order to create the effect of a slideshow. li buttons are all working fine. but whenever ul is clicked, i.e., any area other than li in ul, i'm getting a wrong margin for ul. wud u help me stop the event from firing on ul?

  • 2
    Code is worth 1024 words. – T.J. Crowder Apr 22 '14 at 09:01
  • Before you try to fix it, learn the right terminology of event bubbling and capturing [this question](http://stackoverflow.com/q/4616694/1671639). – Praveen Apr 22 '14 at 09:02
  • @T.J.Crowder, all i want is to prevent the execution of the event that causes the wrong margin to be applied to `ul`. this happens only when i click anywhere outside of `li`. anyway thanks for ur suggeation. – user3559645 Apr 22 '14 at 09:03

1 Answers1

1

You can use event.stopPropagation():

Prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

For example:

$('ul').on('click','li',function(event) {
    event.stopPropagation()
});
Felix
  • 37,892
  • 8
  • 43
  • 55