Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/06/2008, 04:54
Avatar de ZiTAL
ZiTAL
 
Fecha de Ingreso: marzo-2004
Ubicación: Bermio (Bizkaia)
Mensajes: 1.545
Antigüedad: 21 años
Puntos: 62
Eliminar todos los elementos hijos de un elemento

Código:
function removeAllChilds(a)
 {
 var a=document.getElementById(a);
 while(a.hasChildNodes())
	a.removeChild(a.firstChild);	
 }
Aquí un ejemplo:
Código HTML:
<html>
<head>
</head>
<body>
<div id="a">
<span id="1">111111111111111111</span>
<div id="2">22222222222222222222</div>
<strong>aasdad</strong>
</div>
<script type="text/javascript">
function removeAllChilds(a)
 {
 var a=document.getElementById(a);
 while(a.hasChildNodes())
	a.removeChild(a.firstChild);	
 }
 removeAllChilds('a');
</script>
</body>
</html> 

para que usarlo? Pues para alternativa a innerHTML=''

;)
__________________
http://zital.no-ip.org
____________________

Euskerie ahuen eta bijotzan