1

I've this problem

I've some element, actually <li> elements, and over these element I've one operation applied to them, easily done like this:

$('.panelTabs li').on('click', function () {
  // ..some operation that change some tab associated to the list
});

then in my code i need to apply another click operation that has to check if I can execute the previous operation or not.

$('.panelTabs li').on('click', function (ev) {
  // ..some operation that makes some check
  if(bActiveRequests === 0){
    ev.stopPropagation();
  }
});

but the first function is applied before the second function containing the check, so of course my stopPropagation() cannot work, because it's executed after.

So I'm asking if there is a way to add anticipate a click function before a function already applied to the same element.

  • I thought about saving that function in a variable, then remove that function from the li, then add my function, then add the previous function... but that's a bit tricky and not nice at all.

  • I could include my second JavaScript file before the first one. But that is a bit tricky as well because of the code.

Any ideas?

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
axel
  • 3,778
  • 4
  • 45
  • 72
  • 1
    Why not have the first click event make a call to a `CanContinue` function that performs the validation and potentially cancels the event? – xDaevax Aug 20 '14 at 14:23
  • 1
    why don't you merge these functionalities into one event callback? – sunpietro Aug 20 '14 at 14:23
  • the first function is something general applied to all `
  • ` elements that has a generic behaviour (tab switching) in different parts of the website - the second check is something specific only for that `
  • `. that's the reason why i can't merge functionalitis or create a CanContinue function.
  • – axel Aug 20 '14 at 16:54