I don’t know how to access only one of the children of a class created dynamically. (when you click, for example, on the 5th element, then the console displays 5 times), here is an example code:
$('#next').click(function() { var rnd = Math.floor(Math.random()*1000); var html = '<div>'+rnd+'</div>'; $(html).attr('id', rnd).addClass('order').prependTo('#orders'); console.log(rnd); $('.order').click(function() //тут проблема { console.log($(this).attr('id')); }); });
.order { display: block; padding: 5px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id='next'>More</button> <div id='orders'> <div class='order'>Y</div> <div class='order'>X</div> </div>