12 - Agregar un nodo de texto (appendChild - createTextNode)


Confeccionar una página que contenga una lista de tipo (ul) y definir tres marcas de tipo (li) sin texto. Luego al presionar un botón agregar un nodo de texto a cada marca (li).
<html>
<head>
<title>Problema</title>
<script language="javascript" src="funciones.js" type="text/javascript"></script>
</head>
<body>
<ul>
<li id="opcion1"></li>
<li id="opcion2"></li>
<li id="opcion3"></li>
</ul>
<input type="button" value="ver soluciones" onClick="mostrarSoluciones()">
</body>
</html>
function mostrarSoluciones()
{
  var nt;
  var obj;

  nt=document.createTextNode('Respuesta 1');
  obj=document.getElementById('opcion1');
  obj.appendChild(nt);

  nt=document.createTextNode('Respuesta 2');
  obj=document.getElementById('opcion2');
  obj.appendChild(nt);

  nt=document.createTextNode('Respuesta 3');
  obj=document.getElementById('opcion3');
  obj.appendChild(nt);
}

Ver solución
pagina1.html



funciones.js