Add onclick event to newly added element in JavaScript December 28, 2022 by Tarik .onclick should be set to a function instead of a string. Try elemm.onclick = function() { alert('blah'); }; instead.