Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Loop adding Listeners to objects

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a game where there are 9 grids all in one larger grid. I had a few rather complex ideas before realizing I could simplify it by making each grid it's own. Anyway, I needed each grid to listen for it being clicked on. I need it to be able to identify which grid it is specifically so I thought the easiest way to do that would be to loop through the children of the main grid and add a listener to each. But, for some reason the listener only works for one of them. And on top of that, it's the second one. It's a bit hard to give a full functional version of the code because it's a bit at the point where everything is pretty strongly interconnected but here's an example:


Everything works except for the listener
 
Tom Josephits
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I'm a moron. I left a bit in the loop that I forgot to change when I was switching things around.
 
Marshal
Posts: 70257
282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tom Josephits wrote:Never mind. I'm a moron. . . .

No, you aren’t. You just needed a bit of rubber‑ducking.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic