Skip to main content

Posts

Showing posts with the label preventdefault

jquery avoid multiple requests preventDefault

I need a way to prevent multiple submits: $("#myDiv").click(function(e) { e.preventDefault(); console.log('open'); // submit the form $('#myDiv #myInput').click(function(e){ e.preventDefault(); /* ajax call here */ console.log('clicked'); }); }); So if when I click #myDiv is sending X times click to the child function. eg. if you click 3 times #myDiv and then click #myInput will send 3 times the form, and if you press again will send 6. Any ideas how to fix it?