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.
Comments
Post a Comment