0

It is easy to add text in page after loading thanks to javascript but I would like to add a link with a link and be able to catch the click event without reloading page

$("#div").html("<a href='#' id='new'>new link</a>");


// not work, because no 
$("#new").click(function(e) {
    e.preventDefault();
    alert('click');
});

Do you know if there is a way ?

Pipo
  • 5,170
  • 7
  • 33
  • 66

1 Answers1

0

replace

$("#new").click(function(e) {
    e.preventDefault();
    alert('click');
});

with

$(document).on('click','#new',function(e) {
    e.preventDefault();
    alert('click');
});
Cerlin
  • 6,622
  • 1
  • 20
  • 28