Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/09/2010, 16:29
Avatar de Adler
Adler
Colaborador
 
Fecha de Ingreso: diciembre-2006
Mensajes: 4.671
Antigüedad: 17 años, 4 meses
Puntos: 126
Respuesta: appendChild pero que lo coloque encima

Hola

Aquí tienes una adaptación que puede que te ayude
Código Javascript:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <script type="text/javascript">
  6. <!--
  7. var arr = ['mensaje 1', 'mensaje 2', 'mensaje 3'];
  8. function f (){
  9. var divmsg = document.getElementById('mensajes');
  10.  
  11. for (var i = 0; i < 3; i++) {
  12. donde = document.getElementById('p'+parseInt(i-1))
  13.  
  14. var nodo = document.createElement('p');
  15. nodo.setAttribute("class", "rojo"+i);
  16. nodo.setAttribute('id', 'p'+i);
  17. nodo.innerHTML = arr[i];
  18.  
  19. if (divmsg.getElementsByTagName('p').length == 0) {
  20. divmsg.appendChild(nodo);
  21. } else {
  22. divmsg.insertBefore(nodo, donde);
  23. }
  24. }
  25. }
  26. //-->
  27. </script>
  28.  
  29. <style type="text/css">
  30. <!--
  31. p {border: 1px solid black}
  32. p.rojo0 {background-color: red}
  33. p.rojo1 {background-color: green}
  34. p.rojo2 {background-color: yellow}
  35. -->
  36. </style>
  37.  
  38. </head>
  39. <body>
  40. <div id="mensajes"></div>
  41.  
  42. <input type="button" value="Mensajes" onclick="f();" />
  43. </body>
  44. </html>
Suerte
__________________
Los formularios se envían/validan con un botón Submit
<input type="submit" value="Enviar" style="background-color:#0B5795; font:bold 10px verdana; color:#FFF;" />