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

python - jinja2: TemplateSyntaxError: expected token ',', got 'string' -

Qt4: how to send QString inside a struct via QSharedMemory -

node.js - NodeJS remote terminal to Dropbear OpenWRT-Server -