Why is the link not working if the link is created with javascript? It only works if I make the link without the html() output
Not working
$(".link").on('click', function(){
alert('Hello');
});
$("#link").html('<a href="#" class="link">Link</a>');
<div id="link"></div>
Working
$(".link").on('click', function(){
alert('Hello');
});
<a href="#" class="link">Link</a>