I have dynamically created element below. how can I attach an event on click when a button is clicked.
Ex: when button tag in ID item1 is clicked. I will get the h5 tag value. and so as item2 when button ID item2 is clicked will get the h5 tag on item2 value.
I try the ff. jquery but it return the h5 of all item1 and item2.
$('#Id').on('click','.myclass', function() {
var text = $(this).parent().text();
alert(text);
});
<div id="Item1" class="toolimg">
<div class="dplicon"></div>
<center>
<h5>Item1</h5>
<button class="btn btn-primary">Download</button>
</center>
</div>
<div id="Item2" class="toolimg">
<div class="dplicon"></div>
<center>
<h5>Item2</h5>
<button class="btn btn-primary">Download</button>
</center>
</div>