Skip to content

Instantly share code, notes, and snippets.

@fmagrosoto
Created April 4, 2024 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmagrosoto/00854f159b5e286bfd948109b5002038 to your computer and use it in GitHub Desktop.
Save fmagrosoto/00854f159b5e286bfd948109b5002038 to your computer and use it in GitHub Desktop.
Borra de manera recursiva los hijos de un elemento, usando javascript y while
/**
* ELIMINAR DE MANERA RECURSIVA A LOS HIJOS DEL ELEMENTO PASADO COMO PARÁMETRO
*
* @author Fernando Magrosoto V.
* @since abril, 2024
*/
function borrarHijosRecursivamente(elemento) {
while (elemento.firstChild) {
elemento.removeChild(elemento.firstChild);
}
}
// Ejemplo de uso:
const miElemento = document.getElementById("miElemento");
borrarHijosRecursivamente(miElemento);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment