Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/07/2012, 08:48
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: appendChild y error en IE

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. var n= 0;
  9. function agregarItem(){
  10. n++;
  11. var destBoton = document.getElementById('ulItem');
  12. var item = document.createElement('li');
  13. item.id = "item" + n;
  14. var texto = "<div>hola<\/div>";
  15. item.innerHTML = texto;
  16. destBoton.appendChild(item);
  17. }
  18. //]]>
  19. </head>
  20. <div>
  21.  <ul id="ulItem"><li style="list-style-type: none;"><!-- fix --></li></ul>
  22.  <div class="agregar">
  23.  <span onclick="agregarItem();" style="cursor: pointer"> Agregar</span>
  24.  </div>
  25. </div>
  26.  </body>
  27. </html>

Con solo declarar las variables se solucionaría, de paso algunas correciones
el contador n iniciarlo en el script, un li sin estilo para corregir el xhtml, y un span con estilo cursor para el "agregar"

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.