How to clone div easily?

<%= @topic_view.topic.title %>
<%= @topic_view.topic.average_rating %> <%= @topic_view.topic.posts.count { |p| !!p.custom_fields['rating'] } %>

Hello I would like to copy or clone my div six times I found this way to do it but I was wondering if there is another way to do it more easily with less code?

code
http://jsfiddle.net/zvdekh8p/4/

html

<div id="test">Hello World</div>

js

var myDiv = document.getElementById("test");

document.body.appendChild(myDiv.cloneNode(true));
document.body.appendChild(myDiv.cloneNode(true));
document.body.appendChild(myDiv.cloneNode(true));
document.body.appendChild(myDiv.cloneNode(true));
document.body.appendChild(myDiv.cloneNode(true));
document.body.appendChild(myDiv.cloneNode(true));

Using a loop would be less code.

2 Likes