Como se pueden asignar varios eventos iguales a un elemento en javascripts sin usar jquery. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Como se pueden asignar varios eventos iguales a un elemento en javascripts sin usar jquery.

Como puedo hacer que se ejecute uno por uno (sin que se ejecuten al mismo tiempo).

22nd Apr 2021, 7:49 PM
Esteban
Esteban - avatar
4 Answers
+ 1
Para que se ejecute cada evento en orden y no se ejecuten al mismo tiempo, debes colocar un bucle y con ayuda de los condicionales detenerlo. ejemplo: var mensaje=document.getElementById('mensaje'); var enviar=document.getElementById('enviar'); var cero = 0; enviar.addEventListener("click", function (){ cero++; if (cero == 1){ mensajeuno.innerHTML=texto.value; } if(cero == 2){ mensajedos.innerHTML=texto.value; }
23rd Apr 2021, 9:02 PM
Esteban
Esteban - avatar
+ 1
In vanilla JavaScript, you can attach various event listeners to elements. If you want, you can attach more than one listener to the same element. When you attach multiple listeners to the same element, those listeners can target the same event (but you might want to avoid this) or different events. You add listeners using addEventListener(). For example, if you have a form element which in your JavaScript you might have called contactForm, you can do this to attach different listeners which will run the associated functions you pass in: //handleFocusIn will be invoked every time the form focusin event fires form.addEventListener('focusin', handleFocusIn) // see comment for handlFocusIn form.addEventListener('focusout', handleFocusOut);
22nd Apr 2021, 9:04 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
0
++c
24th Apr 2021, 7:39 AM
Евгения Тимченко
Евгения Тимченко - avatar