My problem is:
When I press the "Show numbers" button, Javascript dynamically create two elements whose class is "number". I expect the computer will console the text of the element which I click. But no matter how hard I try to click the elements, my computer console nothing.
HTML (Pug):
button#btn show numbers
.numberlist
Produced HTML:
<button id="btn">show numbers</button>
<div class="numberlist"></div>
JavaScript:
$("#btn").click(
function(){
$(".numberlist").html("<div class='number'>1</div><div class='number'>2</div>");
}
);
$(".number").click(
function(){
console.log("You click number "+$(this).text());
}
);
It's the page on Codepen.