Please help I have struggled on this with my cookie clicker-like game and I can't figure it out.
Asked
Active
Viewed 23 times
-1
-
Elaborate more on your problem please. snippet/visual etc... – emre-ozgun Nov 05 '21 at 19:13
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 06 '21 at 21:45
1 Answers
0
Sounds like 'event delegation' would be useful Assuming your image includes some distinguishing factor (className or id); Basically add an event listener to the whole container/window and observe if className matches with your image else do nothing
const imageClickObserver = (e) => {
if(e.target.className === 'image') {
cookiePoints++;
alert('clicked on image')
}else {
return;
}
}
window.addEventListener('click' imageClickObserver)
If I misunderstood your question and all you care of is to make your elements 'clickable'/'not clickable' then you can read this thread. Add CSS cursor property when using "pointer-events: none"

emre-ozgun
- 676
- 1
- 7
- 17