-2

How can i copy 1 div element with 3 child elements in it,for like 12 times with javascript.Here is what i have done and it isn't working...

$(document).ready(function(){
 for (var i=1;i<12;i++){
      document.getElementByClassName("food-content").innerHTML += 
     "<div class='food-group'><a>Link " + i + "</a></div>";
 }
 
});

And here is my HTML elements which i want to copy.

<div class="food-col1">
<div class="food-group">
<a>Убвец!<img src="http://image.prntscr.com/image/4b52e3e1db8f43cfb2f7c9829f4bebde.png"></a>
</div>
</div>
Dako
  • 51
  • 2
  • 10

1 Answers1

2

There is no function getElementByClassName, only getElementsByClassName which will return an array, so you'd need:

document.getElementsByClassName("food-content")[0].innerHTML

NikxDa
  • 4,137
  • 1
  • 26
  • 48
  • It isn't working ;/ im hopeless – Dako Dec 10 '16 at 15:58
  • Please show your updated code. – NikxDa Dec 10 '16 at 15:58
  • http://pastebin.com/Ldv2RKNZ Sorry don't know how to add code to comment lol.. – Dako Dec 10 '16 at 16:12
  • http://codepen.io/anon/pen/QGBBZK Works completely fine for me. – NikxDa Dec 10 '16 at 16:16
  • It isn't working in my page here is what i tried.(working on wordpress) 1.Connect my file with – Dako Dec 10 '16 at 16:25
  • There is example of what i am trying to do:http://prntscr.com/dhqh68 (its a table with div elements) There is what i have at the moment:http://prntscr.com/dhqhlw Haven't worked on style ,i wanna copy it first. – Dako Dec 10 '16 at 16:27