Href Links Dymamically
<p>I have some links in an json file</p>

<pre><code>&lt;code&gt;
"links": [
            {"link": "http://www.google.com/",
             "id": "1"
            },
            {"link": "http://www.poogle.com/",
             "id": "2"
            },
            {"link": "http://www.foogle.com/ ",
             "id": "3"
            },

]
&lt;/code&gt;
</code></pre>

<p>on a webpage, I will like a js function or script that will write in the url  href dynamically </p>

<p>So if im on a page and the href is </p>

<pre><code> &lt;a href  id=”1”&gt; &lt;/a&gt;
</code></pre>

<p>it should be able to write in google.com into that ahref.</p>

<p>Also is this the best approach to take, should I use Id? Or something else?</p>

<p>Your insight will be helpful</p>

<p>UPDATED</p>

<pre><code>JSON FILE:

{"links": 

[
            {"link": "google.com",
             "id": "1"
            },
            {"link": "yahoo.com",
             "id": "2"
            },
            {"link": "msn.com",
             "id": "3"
            },
            {"link": "mash.com",
             "id": "4"
            },
            {"link": "facebook.com",
             "id": "5"
            }
        ]

}
</code></pre>

<p>JS</p>

<pre><code>for (var i = 0; i &lt; linksObj.links.length; i++) {
    var linkObj = linksObj.links[i];
    var elem = document.getElementById(linkObj.id);

    if (elem) {
       elem.href = linkObj.link;
       elem.innerHTML = linkObj.link;
    }
}
</code></pre>

<p>HTML</p>

<pre><code>&lt;a id='1'&gt;&lt;/a&gt;&lt;br&gt;
&lt;a id='2'&gt;&lt;/a&gt;
</code></pre>
