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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -