The Selected One
The Selected One

Reputation: 77

taking image from the same folder as script.js but image does not load up

Taking image from the same folder the index and javaScript files are in, but for some reason it does not load. And the error it gives me is,

"Failed to load resource: the server responded with a status of 404 (Not Found)"
var img = dcoument.createElement("IMG");
img.height = 500;
img.width = 340;
img.src = '/img.jpg';

document.getElementById("addImgHere").appendChild(img);

Upvotes: 1

Views: 1174

Answers (1)

Abhishek Anshu
Abhishek Anshu

Reputation: 46

Your code works just fine.

You have two issues in your code:

  1. You have given image path as '/img.jpg'. It should be './img.jpg'
  2. You have spelled document wrong in line 1.

Incorrect:

var img = dcoument.createElement("IMG");

Correct:

var img = document.createElement("IMG");

Upvotes: 3

Related Questions