Last active
November 24, 2019 00:05
-
-
Save grekodev/02738fe632120e0773276535735fc589 to your computer and use it in GitHub Desktop.
clonar_elementos_dom.js
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
<script type="text/javascript"> | |
window.addEventListener("load", function(e) { | |
let templete = document.getElementById("article-template"); | |
let articles = document.getElementById("articles"); | |
for (let i = 1; i <= 5; i++) { | |
let clonar = templete.cloneNode(true); | |
clonar.removeAttribute("id"); | |
let h2 = clonar.getElementsByTagName("h2")[0]; | |
h2.innerHTML = h2.textContent + " " + i; | |
articles.appendChild(clonar); | |
} | |
}); | |
</script> | |
<!--LISTADO ARTICULOS--> | |
<div id="articles"> | |
<article class="article-item" id="article-template"> | |
<div class="image-wrap"> | |
<img | |
src="https://cflvdg.avoz.es/default/2016/06/07/00121465331825011951185/Foto/.jpg" | |
alt="Paisaje" | |
/> | |
</div> | |
<h2>Articulo de Prueba</h2> | |
<span class="date">Hace 5 min</span> | |
<a href="">Leer más</a> | |
</article> | |
<!-- Anadir articulos via js --> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment