因为一段代码胜过千字
// this is our dynamic created element.,
var $test = $('<button>If you add this event is working, if you remove this, and add again, event is not working...</button>');
// this is our event
$test.click(function(){
alert('Fooobar'); // fires only first time
});
// $test.on('click',function(){ <-- same behaviour
$('#add').click(function(){
$('#container').append( $test );
});
$('#remove').click(function(){
$('#container').html(''); // This is destroying all $test events!!!
});
如何删除元素,再次附加并保存事件?
JS小提琴:
我想删除元素而不破坏事件。