0

So I've had this problem for a few hours, and I've researched all the other answers and they all say that it has to do with assigning an event to a dom element that doesn't exists yet. The weird thing is: some of the problem dom elements work and some don't, and the pattern is VERY random. If anyone has any ideas of what could be causing this issue, it would be greatly appreciated.

here is my js code:

$(document).on('click', '.user_word_list_item', function(event) {
  event.preventDefault();
  console.log('worked!');
});

and here is my handle bar template:

<script id="player-word-template" type="text/x-handlebars-template">
  {{#each user_words}}
  <a class="user_word_list_item" id="user_word{{id}}" href="#">{{name}}</a>
  {{/each}}
</script>

this is a link to my project on github https://github.com/laomatt/wordtris/blob/master/app/assets/javascripts/games.js lines 238

and the view file: https://github.com/laomatt/wordtris/blob/master/app/views/games/show.html.erb

matt lao
  • 331
  • 1
  • 2
  • 11

1 Answers1

0

I solved this issue, I had to set up and anchor tag in the jQuery binding. So it had to be:

 $(document).on('click', 'a.user_word_list_item', function(event)
matt lao
  • 331
  • 1
  • 2
  • 11