Search code examples
javascriptevent-propagation

Javascript: stopPropagation only works the first time?


My button is only being 'clicked' the first time it is clicked. Every time after, the click event is immediately propagated to the parent's onclick. Here is the button's onclick:

$('.clickable .moveUp').click(function(e) {
        moveUpWorkoutExercise($(this));
        e.stopPropagation();
    });

And the HTML outline:

<div class="clickable" onclick="toggleExerciseDetails(311,false)">
    <a class="moveUp disabled" title="Move this exercise up"></a>

How can I make the event work every time and not just the first time? Thanks!


Solution

  • If an error occurs within the moveUpWorkoutExercise() function then execution of your event handler will stop before it gets to the e.stopPropagation(); line. Is there something in that function that might break for second and subsequent clicks?

    (You could try putting e.stopPropogation() first and see what happens, but hypothetically if that does "work" it hasn't really fixed the underlying problem.)