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
Jochem14mo ago
I'm guessing maybe "something like" isn't quite close enough cause that works as expected
Aldrin
Aldrin14mo ago
yes its working fine on code pen, not sure why not working on my project
Jochem
Jochem14mo ago
is this the exact code in your project?
Aldrin
Aldrin14mo ago
yes same structure
Aldrin
Aldrin14mo ago
No description
Jochem
Jochem14mo ago
it's stopPropagation with a capital P
Aldrin
Aldrin14mo ago
still not woking
Mannix
Mannix14mo ago
exact same code btw 🤣
Jochem
Jochem14mo ago
well, when I put stoppropagation in the codepen, I got a console error. Do you get any errors in your console?
Aldrin
Aldrin14mo ago
no actually its not triggering only
Jochem
Jochem14mo 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
Aldrin14mo ago
ok
Jochem
Jochem14mo ago
there's tips in #how-to-ask-good-questions for sharing your code
Aldrin
Aldrin14mo ago
can't share the whole project here, so shared a small part
Jochem
Jochem14mo 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
Aldrin14mo 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