2
I have two functions that need to interact in the same DIV
.
# ambientEdit(this);
Her job is to keeping DIV pressed for 3 seconds, open the screen of confirm()
javascript, passing the ID.
# survey Start(this);
This function, when clicking only once in the DIV is forwarded to another screen passing some parameters.
Trying:
<div class="lista fade" onclick="ambienteEdit(this);vistoriaIniciar(this)">
vistoriaIniciar()
, works, but the ambienteEdit()
does not work. If I remove the vistoriaIniciar()
the function ambienteEdit()
works.
Question:
How to have both events in the same DIV
?
Thank you.
function ambienteEdit(object) {
let aID = object.getElementsByClassName('aID')[0].value;
let delay;
document.addEventListener("mousedown", function() {
delay = setTimeout(_ => confirm("Dialogo"), 3000)
});
document.addEventListener("mouseup", function() {
clearTimeout(delay);
});
console.log(aID)
}
function vistoriaIniciar(object) {
let aID = object.getElementsByClassName('aID')[0].value;
let aCodigo = object.getElementsByClassName('aCodigo')[0].value;
let aNome = object.getElementsByClassName('aNome')[0].value;
window.location='vistoriaIniciar.html?codigo='+aCodigo+'&ambiente='+aNome+'&id_ambiente='+aID;
}
<div class="lista fade" onclick="ambienteEdit(this);vistoriaIniciar(this)">
BLA BLA BLA
</div>
Error appears in CONSOLE?
– PauloHDSousa
@Paulohdsousa No mistake, just does not execute the
ambienteEdit
.– Tiago
Why do you want the system to wait 3 seconds to open a confirmation?
– Daniel Santos
Take a look here: https://stackoverflow.com/a/52751982/11890088
– ivansnpmaster
@Danielzazula because it’s something I’m doing for cell phone. In the same DIV the person passes to another screen, but if the person keeps pressed will open the edit screen.
– Tiago
Deliberately adding a Document.addeventlistener to every click is wrong, both in your question and in the answers, this is not how you use the listening events, it may even work, but it is not correct and records a number of things that are no longer being used, consuming what does nothing after the first addition.
– Guilherme Nascimento