1
<img id="opeth"> </img>

<script type="text/javascript">
    var gearpics = [];
        document.getElementById("opeth").innerHTML = gearpics;

    var prs = new Image();
    prs.onload = function() {
    };
    prs.src = src

    var prs2 = new Image();
    prs2.onload= function() {
    };
    prs2.src = src

    var prs3 = new Image();
    prs3.onload= function() {
    };
    prs3.src = src
function insert() {
    gearpics.push(document.getElementById('opeth').src = prs.src);
    gearpics.push(document.getElementById('opeth').src = prs2.src);
    gearpics.push(document.getElementById('opeth').src = prs3.src);
    }
</script>

This is my code. When I run it, and press the "Show pictures" button, only the third picture (id=prs3) appears. I want all of them to show up.

Jon P.
  • 23
  • 2
  • 1
    you are setting all 3 pictures to the same ID. The 3rd one is showing up because that's the last one being set to that ID. If you create 3 img tags and push each picture to a different ID, they should all show up – erichardson30 Feb 11 '16 at 15:40
  • 1
    `` That's illegal html. img tags are singletons and cannot have any content. – Marc B Feb 11 '16 at 15:43
  • Possible duplicate of [Javascript set img src](http://stackoverflow.com/questions/1232793/javascript-set-img-src) – AleFranz Feb 11 '16 at 16:30

1 Answers1

1

You are using the same ID for your 3 pictures:

gearpics.push(document.getElementById('opeth').src = ...);

ID should be unique in HTML document.

Simon PA
  • 748
  • 13
  • 26