Created
April 4, 2024 18:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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