Is there an event for onclick end?
10,475
Solution 1
As per comment:
document.getElementById('trigger-box').addEventListener("mouseup", function(e) {
// the event will be used later
// my code
});
Solution 2
onmouseup
happens before the click
event is executed
<button onclick="console.log(1)" onmouseup="console.log(2)">test</button>
Therefore, the only workaround I can think of is manually calling when the click
event is completed
function myClick()
{
console.log('This is in click');
afterClick();
}
function afterClick()
{
console.log('This is after click');
}
<button onclick="myClick()" >test</button>
Author by
Mudassir
Computer Science and Mathematics student. More than just an ASCII character in the terminal.
Updated on June 04, 2022Comments
-
Mudassir almost 2 years
I have a code in which should only be executed after an onclick event. On mobile devices its fine because I use touchstart and touchend. Is there an event similar to touchend for use on a computer?
My code currently looks similar to..
document.getElementById('trigger-box').addEventListener(function(e) { // the event will be used later // my code });
I have tried searching the internet for an answer but unfortunately couldn't find an answer. Therefore, I have posted my question here.
-
KarelG almost 9 yearshmm, it works but I really don't recommend embedded click events in HTML ... And please use
console.log(<String>)
for debug purposes -
AmmarCSE almost 9 years@KarelG, sorry if the alerts where annoying. Updated my answer to use console.log.
-
David Callanan almost 4 yearsI believe it is necessary to use "touchend" on mobile.