user544079
user544079

Reputation: 16639

Prevent a event from propagating further using jQuery

I have a click event

<input type="button" id="button1" value="Submit" />

$('#button1').bind('click', function(e){
    e.stopPropagation();
    e.stopImmediatePropagation();
    alert('Loading, please wait...');
});

However, the alert message is not prevented from showing up. How can the event be stopped before alert.

Upvotes: 0

Views: 49

Answers (2)

Deepu--Java
Deepu--Java

Reputation: 3840

$('#button1').bind('click', function(e){
        return false;
        alert('Loading, please wait...');
    });

Use this.

Upvotes: 2

You need return false; for what are you trying to do here..

$('#button1').bind('click', function(e){
    e.stopPropagation(); //stops propogation of click to parent elements
    return false; //stops further execution
    alert('Loading, please wait...');
});

Demo Fiddle

Upvotes: 3

Related Questions