0

I have normal elements where my jQuery code is working as expected.

<div class="upperClass">
  <span class="entry" sub-id="1"></span>
  <span class="entry" sub-id="2"></span>
  <span class="entry" sub-id="3"></span>
</div>

jQuery:

$(document).ready(function() {
    $('.entry').click(function () {
          console.log("A");
    });
});

A gets logged in the console as expected. Then I dynamically create span elements with jQuery and append.

<span class="entry" sub-id="4"></span>
<span class="entry" sub-id="5"></span>

But dynamically created spans don't log anything.

senty
  • 12,385
  • 28
  • 130
  • 260
  • Why didn't you close your HTML tags? That could be your problem. – programking Oct 24 '15 at 00:16
  • @King What do you mean? I've close them normally. This is just a snippet code. @MinusFour I am using `click()` rather than `on()`, so I couldn't figure out how to adapt `eventName, selector, function` – senty Oct 24 '15 at 00:20
  • 1
    You're missing the `>` at the end of `` – Barmar Oct 24 '15 at 00:21
  • @Barmar I fixed it. It was just my question being wrong. @MinusFour, I tried `$('.hello').on('click', 'upperClass', function () {` but that works for normals but not dynamically created ones either :/ – senty Oct 24 '15 at 00:22
  • Which is the dynamically created element? It should be `$(".upperclass").on("click", ".entry", function() { ...` – Barmar Oct 24 '15 at 23:34

0 Answers0