13
What would be the 'e' that is passed as a function parameter? Ex.:
function nome(e) {
(instrução);
}
Does anyone have any material, or keyword for research that I can turn to to study a little more on the subject?
13
What would be the 'e' that is passed as a function parameter? Ex.:
function nome(e) {
(instrução);
}
Does anyone have any material, or keyword for research that I can turn to to study a little more on the subject?
20
It is common to name e
as an abbreviation of event
, to pass a reference to the object Event used in callback functions event receiver. Short for convenience and to save bytes.
The object Event in itself is useful for example:
e.preventDefault();
(example)e.type
e.target
etc....
Thanks a lot, Sergio! Abs.
I get it,,, vlw man...
3
In this case this 'e' is a specific parameter in specific functions, such as events.
It is very common in jQuery. For example, when we create an onclick
at a link:
$('#link-legal').on('click', function(e) {
alert('Link legal clicado!');
});
In this case, this 'and' parameter (which can actually have any name, but the letter 'and' which is short for 'Event') will contain the link object clicked with several properties and methods.
Let’s say you want, when clicked on a link, to be asked a confirmation to the user and, depending on its response, the click is 'canceled':
$('a.confirmar').on('click', function(e) {
var confirmado = confirm('Deseja realmente prosseguir para esse link?');
if(confirmado == false) {
e.preventDefault();
alert('Click cancelado');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a href="https://www.google.com" target="_blank" class="confirmar">Ir para o Google</a>
In this example we use the method preventDefault
which cancels the standard action of the element, which in the case of the tag <a>
is the path to the url indicated in the property href
.
Usually in the documentations you find this type of reference, as you can check in the official documentation of jQuery for the event click
:
There it says (in free translation):
.click( Handler ) Handler Type: Function( Event eventObject ) A function that will be executed at each event trigger.
You can see in the guy it says that a Function
in which an object parameter of the type is passed Event
.
Just remember that the object passed by jQuery is not equal to the native JS event, but a normalized version. Or at least it used to be like this, they may have changed in the newer versions of jQuery.
Browser other questions tagged javascript jquery
You are not signed in. Login or sign up in order to post.
good sites to study would be: http://www.codecademy.com/pt-BR/tracks/javascript and http://www.codecademy.com/pt-BR/tracks/jquery
– Andrey Hartung