I am using dust.js ( after much googling for a lack of good documentation ). Finally I was able to create a hyperlink dynamically.Now I want to give an onclick functionality to the dynamically generated hyperlink.
function createLink(){ // register the template loading method with dust now var compiled = dust.compile("Hello <a href='#' id='linked'>{name}</a>!", "intro"); dust.loadSource(compiled); dust.render("intro", {name: "Fred"}, function(err, out) { console.log(out); $("#displayHelloSection").html(out); }); } Below is my document ready. Strangely , when I click on the hyperlink generated , I get Apple , but not Orange. I am curious to know why the second onclick did not work ? The difference is ,In the first one , I am using document to refer to my id ('#linked').In the second one I am directly accessing the id.
$(document).ready(function() { $(document).on('click','#linked',function(e){ alert("Apple"); }); $('#linked').on('click', function() { alert('Orange'); }); });