0

I have this bit of code that is supposed to output test and then basically do stuff to a div tag. There is some sort of syntax error in it though that outputs" Uncaught SyntaxError: Unexpected identifier" code:

<script type="text/javascript">
    console.log("test");
    document.getElementById("file").onchange = function(){
        var div = getElementById("imageContainer");
        for each(var image in document.getElementById("file").files){
            div.appendChild("<img src=" + image + "/>");
        }
    };
</script>
1
  • The real cause of the error is for each Commented Nov 7, 2018 at 6:49

1 Answer 1

3

Change:

var div = getElementById("imageContainer");

To:

var div = document.getElementById("imageContainer");

getElementById is a member of the document object.

Sign up to request clarification or add additional context in comments.

1 Comment

@DominicOryema You should accept this answer if it solves your problem, notice the check mark to the left right below the voting arrows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.