Printing all the id names for a class in javascript : <p>I want print the Id of every element that has the class name "test". Right now nothing is printing. I would like this to print </p>

<pre><code>myAnchor
SecondId
</code></pre>

<p>I left my comments in there to show how an Id can be printed by accessing the Id name</p>

<p>This is my script</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;p&gt;&lt;a id="myAnchor" class="test" href="http://www.w3schools.com/"&gt;W3Schools&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a id="SecondId" class="test" href="http://www.w3schools.com/"&gt;Second&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click the button to display the value of the id attribute of the link above.&lt;/p&gt;

&lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;

&lt;p id="demo"&gt;&lt;/p&gt;

&lt;script&gt;
function myFunction() {
    //var x = document.getElementById("myAnchor");
    //document.getElementById("demo").innerHTML = x.id;
    var x = document.getElementByClassName("test");
    for(count = 0; count &lt; x.length; count++){
        document.getElementById("demo").innerHTML = x.id;
    }
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>
