appendChild
Hola:
Mi pregunta es la siguiente:
En javascript he hecho una tabla con sus correspondientes celdas y lo he creado de la siguiente manera:
row = document.createElement( "TR" );
tbody.appendChild( row ) ;
cell = document.createElement( "TD" );
row.appendChild( cell );
Me funciona, pero si inserto un <a href=""> no funciona, alguien sabe como hacerlo?
Gracias
Un saludo
Mi pregunta es la siguiente:
En javascript he hecho una tabla con sus correspondientes celdas y lo he creado de la siguiente manera:
row = document.createElement( "TR" );
tbody.appendChild( row ) ;
cell = document.createElement( "TD" );
row.appendChild( cell );
Me funciona, pero si inserto un <a href=""> no funciona, alguien sabe como hacerlo?
Gracias
Un saludo
¿Dónde quieres añadir el enlace? ¿dentro de la tabla?
Haber si esto te vale:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Introducir enlace</title></head>
<body>
<table>
<tr>
<td>hola</td>
<td> como estas </td>
</tr>
<tr>
<td> espero que </td>
<td id="dondeva">aqui enlace: </td>
<td>bien</td>
<script type="text/javascript">
<!--
//document.getElementById("dondeva").removeChild(document.getElementById("dondeva").firstChild)
var contenidoenlace = document.createTextNode("Cuabipe de Itan");
var elementoenlace = document.createElement("a");
elementoenlace.setAttribute("id", "elenlace");
elementoenlace.setAttribute("href", "http://www.iespana.es/cuabipe/");
document.getElementById("dondeva").appendChild(elementoenlace);
document.getElementById("elenlace").appendChild(contenidoenlace);
//-->
</script>
</body></html>
Haber si esto te vale:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>Introducir enlace</title></head>
<body>
<table>
<tr>
<td>hola</td>
<td> como estas </td>
</tr>
<tr>
<td> espero que </td>
<td id="dondeva">aqui enlace: </td>
<td>bien</td>
<script type="text/javascript">
<!--
//document.getElementById("dondeva").removeChild(document.getElementById("dondeva").firstChild)
var contenidoenlace = document.createTextNode("Cuabipe de Itan");
var elementoenlace = document.createElement("a");
elementoenlace.setAttribute("id", "elenlace");
elementoenlace.setAttribute("href", "http://www.iespana.es/cuabipe/");
document.getElementById("dondeva").appendChild(elementoenlace);
document.getElementById("elenlace").appendChild(contenidoenlace);
//-->
</script>
</body></html>