jQuery can't access append element
问题 I have this inside a function: $('#users').append($("<div id='usuarios'>").text(mensaje[1][i])); I want to create an onclick event for this new <div> . How can I achieve this? I'm trying it like this outside the function: $(document).ready(function(){ $('#usuarios').click(function() { alert("click"); }); }); But it doesn't work. 回答1: For jQuery 1.7+ you can attach an event handler to a parent element using .on() $(document).ready(function(){ $('body').on('click', '#usuarios', function() {