javascript - Could not add click event on dynamically created anchor tag -
i trying register click
event on anchor
tag created dynamically not working. following code
var location = 's'; $('#phone').on('click', 'a', function(event) { console.info('anchor clicked!'); event.preventdefault(); return false; }); for(var = 0; < 5; i++) { $("div#phone").append('<ul><a href="#" id = "' + location + '"> rajeev </a></ul>'); }
have @ fiddle
edit updated fiddle link
your code works well, check browser's console or change console alert:
$('#phone').on('click', 'a', function(event) { alert('anchor clicked!'); event.preventdefault(); return false; });
Comments
Post a Comment