jQuery: preventdefault does not work

Posted by Kent Miller on Stack Overflow See other posts from Stack Overflow or by Kent Miller
Published on 2014-06-08T15:20:04Z Indexed on 2014/06/08 15:24 UTC
Read the original article Hit count: 166

Filed under:
|

I somehow cannot achieve that the a-tag looses its default action when clicking it:

<a href="#" class="button dismiss">dismiss</a>

$(document).ready(function() {

        $('.dismiss').click(function(e) {

        e.preventDefault();                                 
        $('#output').empty();                                               
        $('#MyUploadForm .button').show();

        });

});

When I click the button, the browser window scrolls to the top. What is wrong here?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery