javascript - jQuery doesn't catch the event -


i trying use following code jquery selection doesn't catch click event

$('#addlevel').on('click', function() {     var div = '<div class="form-inline">';     var addbutton = '<button  class="btn btn-success additems" onclick="alert()" type="button">Добавить</button>';     div += addbutton;     div += '</div>';     $('#levels').append(div); }); //i assume following code not working why? $('.additems').eq(0).on('click', function() {     alert('clicked'); }); 

thank you

then try add handler .additems there no such dom nodes. @blgt said must use event delegation:

$(document).on('click', '.additems:first', function() {     alert('clicked'); }); 

p.s. better use parent node of .additems:first instead of document.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -