<body>
<script>
function zz(e) {
alert('click handler');
}
addElem("div",
{
id : "newId",
className : "newClass",
textContent: 'Нажми меня',
style :
{
width : "100px",
height: "200px",
background : "#32cd32"
},
onclick : zz
})
function addElem(tag, properties) {
var element = document.createElement(tag);
for (var property in properties) {
switch (property) {
case 'style':
(function(style) {
for (var property in style) {
element.style[property] = style[property];
}
})(properties[property]);
break;
default:
element[property] = properties[property];
}
}
return document.body.appendChild(element);
}
</script>
</body>