Felices Reyes Javier!!!
 
Mira a ver si esta chapucilla te sirve:
   Código PHP:
    <html>
<head>
    <title>Untitled</title>
    <style>
    .a{background:red;
    width:100px;
    height:100px;}
    </style>
</head>
 
<body>
<div id="pru"></div>
<script>
elem=document.getElementById('pru');
elDiv=document.createElement('div');
elDiv.setAttribute('className','a');
elDiv.setAttribute('id','algo');
elDiv.onclick=pepe
function pepe(esto) {alert(esto.id);}
elem.appendChild(elDiv);
 
</script>
<input value="www" type="button" onclick="pepe(elDiv)"/>
 
</body>
</html>