I have a div with HTML, that I am trying to push inside an empty div. The new div should acquire all the content and styling from the original.
Existing content:
<ul id="existing_id" class="my_class">
<strong>Does not show up in new div</strong>
<li class="style">
<p class="style">Shows up in new div</p>
</li>
</ul>
New, empty div - where I push everything from "existing_id" into:
<div id="empty_div"></div>
I am targeting the elements through JS:
var existing = document.getElementById("exisiting_id")
var existing_li = existing.getElementsByTagName("li")
var empty_div = document.getElementById("empty_div")
var myArray = []
empty_div.innerHTML = ""
// Pushing each existing li element inside myArray
for (var i=0; i < existing_li.length; i++) { myArray.push(existing_li[n]; }
function make_it_happen() {
empty_div.innerHTML += myArray.innerHTML
}
I am getting the content from #existing_id
inside the new div - but not the styling associated with each element. Some elements are also ignored such as <strong>Does not show up in new div</div>
Aucun commentaire:
Enregistrer un commentaire