Stopping Default Behavior

function myEventHandler(e){   ...handler code...   e.preventDefault();   return false; }

Occasionally, you might want to prohibit the browser from applying the default handler interaction for the event. For example, you might not want the browser to activate a link, or you might not want to allow a form to be reset. You can stop the default browser action by calling the event.preventDefault() method on the event object passed to the handler.

Get jQuery and JavaScript Phrasebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.