I am trying to add inline onclick event listener with html string which I am updating using jQuery html method but it doesn't seem to work,
it does not seem to add any click event listener also when I inspect element there is no onclick attribute seen.
Am I missing something here, can some one help?
var data = [{
'a': 1,
'b': 2
}, {
'a': 10,
'b': 3
}];
var str = '';
function sendData(e, data) {
console.log(data);
}
data.forEach(function(item) {
str += '<div onclick="' + sendData(item) + '">';
});
jQuery('.container').html(str);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container"></div>