jquery - How to pass event to named function on.('click')? -


i have following trigger in jquery:

$('.text').on('click', '.readless', contract); 

in contract, want use event.preventdefault() doesn't work in firefox, need pass event contract. how do this?

you can this:

$(function () {      // attach event     // new way (jquery 1.7+) - on(events, selector, handler);     $('.text').on('click', '.readless', contract);      function contract(e) {         e.preventdefault();         alert(e.type);     }      // create elements dynamically     $('.text').append('<div class="readless">click me</div>'); }); 

after adding reference of function contract on() method, event or e variable automatically passed function first argument.

fiddle


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -