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 ?

Vivien Pipo
  • 3,876
  • 5
  • 21
  • 52

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,327
  • 1
  • 18
  • 25