JavaScript AJAX Basics (retiring) jQuery and AJAX Posting Data with jQuery

fisnik poroshtica
fisnik poroshtica
14,154 Points

what does mean this?

what does mean "evt" inside this function:

$('form').submit(function(evt) {

});

2 Answers

Michael Liendo
Michael Liendo
15,325 Points
evt

stands for "event" and is often written as just "e" . The argument gets assigned as parameter every time an event happens ie. click, toggle, hover, submit etc.

Depending on the event, there's certain methods that you can trigger. Probably the most common, is in the case of a for being submitted, such as above.

$('form').submit(function(evt) {
   evt.preventDefault();
})

This is most common because without it, the form would submit, causing a refresh of the page--when, for example, you'd really want the form to submit to causing that information to update some fields on the page.

Jesus Mendoza
Jesus Mendoza
23,266 Points

Hey Fisnik,

Everytime an event is triggered an object is passed to the event handler (in this case the event handler is the callback function inside the submit method and the object is the evt parameter).

evt (you can call it whatever you want) is the event object that comes when the click (or any other) event is fired. It has all the information about the event that just happened; like the type of event, who triggered, etc.

In this case the evt object will have information about the form and the submit event.

Good luck!