Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67469

how to display an alert in an Onclick event after dom is loaded

$
0
0

I am stuck with a displaying a simple alert. I have a filter button which is created dynamically using jQuery. With this code I am getting alerts randomly. I am not sure why this is happening?

Please help me to get an alert on each li click instead of random alerts.

$(window).on("load", function() {
  $('#game-categories ul li').each(function() {
    $(this).on('click', function() {
      alert("woohoo working");
    });
  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div id="game-categories"><div class="ais-RefinementList"><ul class="ais-RefinementList-list ais-refinement-list--list"><li class="ais-RefinementList-item ais-refinement-list--item"><div><span><img src="https://staging.roger.com/wp-content/themes/roger-theme/img/icons/u/Slots.svg"></span><br> Slots</div></li><li class="ais-RefinementList-item ais-refinement-list--item"><div><span><img src="https://staging.roger.com/wp-content/themes/roger-theme/img/icons/u/Games.svg"></span><br> Games</div></li></ul></div></div>

Viewing all articles
Browse latest Browse all 67469

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>