Window.onclick

i have this weird issue where window.onclick is not triggering my code looks something like this
window.onload = () => {
window.onclick = function() {
console.log('Click event triggered');
// Your code here
};
}
window.onload = () => {
window.onclick = function() {
console.log('Click event triggered');
// Your code here
};
}
16 Replies
Jochem
Jochem15mo ago
I'm guessing maybe "something like" isn't quite close enough cause that works as expected
Aldrin
AldrinOP15mo ago
yes its working fine on code pen, not sure why not working on my project
Jochem
Jochem15mo ago
is this the exact code in your project?
Aldrin
AldrinOP15mo ago
yes same structure
Aldrin
AldrinOP15mo ago
No description
Jochem
Jochem15mo ago
it's stopPropagation with a capital P
Aldrin
AldrinOP15mo ago
still not woking
Mannix
Mannix15mo ago
exact same code btw 🤣
Jochem
Jochem15mo ago
well, when I put stoppropagation in the codepen, I got a console error. Do you get any errors in your console?
Aldrin
AldrinOP15mo ago
no actually its not triggering only
Jochem
Jochem15mo ago
then there's not much we can do without a running example that shows the problem it's likely a syntax error somewhere. That stopPropagation thing definitely is one, but if there's others the method might not be getting added I can't spot one in your screenshot, but I'm also not a javascript engine so I might be missing something
Aldrin
AldrinOP15mo ago
ok
Jochem
Jochem15mo ago
there's tips in #how-to-ask-good-questions for sharing your code
Aldrin
AldrinOP15mo ago
can't share the whole project here, so shared a small part
Jochem
Jochem15mo ago
when you only share a part, you have to make sure the problem still exists though 🙂 it's like taking your friend's car to the mechanic and saying "mine doens't work, fix it please"
Aldrin
AldrinOP15mo ago
yes, i get it well, its working fine with window,addEventListener anyway thanks for your time ✌️
Want results from more Discord servers?
Add your server