jquery .click() event.preventDefault() not working
is your code surrounded by:
$(function(){
//your code here
});
? or
$(document).ready(function(){
//your code here
});
? , because you should wait until the <a></a>
element is ready before adding your click listener to it. try the code above or place your code at the bottom of the html right before the </body>
tag or just right after the <a></a>
element. that should work
EDIT: since your links are added dynamically call your $( '.filelink' ).click()
function right after they are added
I think you missed $(document).ready()
Please update your code as following:
$(document).ready(function(){
$( '.filelink' ).click( function( e ) {
e.preventDefault();
//do some other stuff here
});
})
Since your links are appended dynamically to the page, you need to use document.on()
to capture the click events.
the syntax for appending event listeners to dynamic content is as follows
$(document).on( event, selector, callback );
so your click handler would become:
$(document).on('click','.filelink',function(e){
e.preventDefault();
//code here
return false;
});