Something like this:
<html>
<head></head>
<body>
<button onclick="elem()">Create element</button>
<script type="text/javascript">
function elem() {
var div = document.createElement('div');
document.body.appendChild(div);
div.id = 'myDiv';
div.innerHTML = 'This is created div element with javascript';
}
var myDiv = document.getElementById('myDiv');
myDiv.onclick = function() {
alert('Hello');
}
</script>
</body>
</html>
I have problem. How call function when i clicik on the created element?
myDiv.onclickinsideelem()