I want to call a function clicking on dynamically generated URLs.
var push_div = '<a href="javascript:void(0)" onclick="myFunc('1')">Hello1</a></div>' + '<a href="javascript:void(0)" onclick="myFunc('2')">Hello2</a></div>';
myFunc(e) {
console.log(e);
}
But I received an error:
Uncaught ReferenceError: myFunc is not defined
Then I modified my code as like:
var push_div = '<a id="1" href="javascript:void(0)">Hello1</a></div>' + '<a id="2" href="javascript:void(0)">Hello2</a></div>';
$(document).on('click', $(push_div).find('a').eq(0), function() {
// my code
});
This is not console me any error however, I cannot detect which hyperlink I clicked. Any idea?