let div = document.createElement('div'); document.body.appendChild(div); div.onclick = function(){alert('alert')}; alert(div.getAttribute('onclick'));