I have created this example where i am trying to set on click event for dynamically created div, but i am not able to get the parameter value which passing while setting click event. In this example i have used array but in reality i am getting json by web service.
$(document).ready(function () {
myfunction();
});
function myfunction() {
var cars = ["Saab", "Volvo", "BMW"];
for (var i = 0; i < cars.length; i++) {
$('<div/>', {
id: 'pnlmyDiv_' + i,
html: '<b>Click Me ' + i + '</b><br>',
style: 'padding:10px;border-width:1px;border-style:solid;margin-bottom:5px;cursor:pointer;'
}).appendTo('#pnlParent');
$("#pnlmyDiv_" + i).on("click", function () {
fnGetMessages(cars[i])
});
}
}
function fnGetMessages(car) {
alert(car);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="pnlParent" style="padding:5px;border:solid">
</div>