Add onclick event to newly added element in JavaScript
You can also set attribute:
elem.setAttribute("onclick","alert('blah');");
.onclick
should be set to a function instead of a string. Try
elemm.onclick = function() { alert('blah'); };
instead.