Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery. click event doesn't work after change event?

Having this sample code:

<input type="text" id="changeid">
<a href="#" id="clickb">click</a>

<script>
    $('#clickb').on("click", function(event){
        alert(1);                             
        return false;
    });

    $('#changeid').on("change", function(event){
        alert(2);                             
        return false;
    });
</script>

When putting something into the text field and click the link immediately, only onchange event fires, but not link click event. Why is that? It seems that the change event is blocking the click event?

like image 451
abiku Avatar asked Sep 13 '12 10:09

abiku


1 Answers

It is blocked by alert. Change alert to console.log you will find two events all fired.

The demo.

$('#clickb').on("click", function(event){
    console.log(1);
    return false;
});

$('#changeid').on("change", function(event){
   console.log(2);                             
   return false;
});​
like image 121
xdazz Avatar answered Oct 20 '22 18:10

xdazz