I have an event, which inserts on the page new DOM element.
How to add event to this new element?
My goal is: when user clicks on the input, old value should purge.
I have tried this:
$('a').on('click', function() {
var newel = '<input type="text" value="test" />';
$(newel).insertAfter($('a'));
});
$('input').on('focus', function() {
alert($(this).val());
$(this).val('');
});
http://jsfiddle.net/WpyUf/
New event doesn’t added to the element, why?
FIDDLE