You can just register it in advance with .on()
: Live demo (click).
$(document).on('click', 'some-selector', function() {
});
or create the dom element newTerm
before appending it and attach the function directly: Live demo (click).
var $newTerm = $(newTerm);
$newTerm.click(function() {
});
Since the selector you're adding to the element is a dynamic id, I'd recommend going with the second approach here. If you want to add a class to the generated elements so that you can delegate .on
to them, use .on
. It's more efficient.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…