title: How to generate multiple a tags with JavaScript?
body: <p>I would like to create multiple <code>a</code> tags to populate a <code>div</code>. Writing this in HTML would take a lot of rows and a JavaScript script would make things easier. Unfortunately, I'm still learning it and I'm looking for some help.</p>
  <p>Below is my HTML code that I want generated using JavaScript, inside <code>div id=&quot;countries&quot;</code></p>
  <pre><code>&lt;div class=&quot;countries&quot;&gt;
    &lt;div id=&quot;Denmark&quot;&gt;
      &lt;h4&gt;Denmark&lt;/h4&gt;
  &lt;!-- number of links is variable to each country --&gt;
      &lt;a href=&quot;https://www.example.com&quot;&gt;Link1&lt;/a&gt;
      &lt;a href=&quot;https://www.example2.com&quot;&gt;Link2&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Some JS code</p>
  <pre><code>let countrySelect = document.getElementsByClassName('countries');
  
  let links = [&quot;https://www.example1.com&quot;, &quot;https://www.example2.com&quot;, &quot;https://www.example3.com&quot;, &quot;https://www.example4.com&quot;, &quot;https://www.example5.com&quot;, &quot;https://www.example6.com&quot;, &quot;https://www.example7.com&quot;, &quot;https://www.example7.com&quot;];
  
  // make an array of countries
  let countries = [&quot;Denmark&quot;, &quot;Spain&quot;, &quot;Italy&quot;, &quot;Slovenia&quot;, &quot;Malta&quot;, &quot;Hungary&quot;, &quot;Austria&quot;, &quot;Czech Republic&quot;];
  
  // make a div
  let makeDiv = document.createElement(&quot;div&quot;);
  // add an ID to div just created
  makeDiv.setAttribute('id', 'country');
  // make an A tag
  let tag = document.createElement(&quot;a&quot;);
  tag.setAttribute('href', links[1]); // multiple links needed...integrate in a loop?
  
  // make a loop to create multiple country divs
  for (let index = 0; index &lt; countries.length; index++) {
    // insert all the elements in the loop
  }
  </code></pre>