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

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -