JavaScript: How do I add an attribute?
<p>I'm trying to add the target attribute to some anchors when a radio button is checked; however it isn't working.</p>

<p>Here is my code:</p>

<pre><code>&lt;body&gt;
&lt;ul id="main"&gt;
    &lt;li&gt;&lt;a href="https://www.google.co.uk/"&gt;Google&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.youtube.com/"&gt;YouTube&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://twitter.com/"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;input type="radio" name="input" id="input" /&gt;
&lt;script type="text/javascript"&gt;
document.getElementById('input').checked = function changeTarget() {
    document.anchors.setAttribute('target', '_blank');
}
&lt;/script&gt;
&lt;/body&gt;
</code></pre>

<p>What am I doing wrong? (Note: I don't want a JQuery solution)</p>

<p>Thanks.</p>

<p>Edit: Phew. Done it thanks to all the answers, here's my final code:</p>

<pre><code>    document.getElementById('input').onclick = function changeTarget() {
    if(this.checked) {
        var b = document.getElementsByTagName('a');
        for (a = 0; a &lt; b.length; a++) {
            b[a].target = '_blank';
        }
    }
}
</code></pre>
