images

+3 william appiah-dankwah · February 15, 2015
i want to place an image in javascript how do you do that? does anyone know? 

Post a Reply

Replies

- page 2
Oldest  Newest  Rating
0 william appiah-dankwah · March 20, 2015
Why is it append child Michael walker I can't see the parent last child relationship in that code :)
0 william appiah-dankwah · March 20, 2015
@michal walker na never worked there's another way though
0 william appiah-dankwah · March 20, 2015

Var image = new image;

image.src = "pic/image.jpeg";

document.body.appendChild(image);

0 michael walker · March 20, 2015
nah it does work it should be

"Var image = new image; "

should be " var image = new Image" - that Image next to new has to start with a capital i.

//My code tested on Dreamweaver CS6 and fully works

var image = new Image;
image.src="Images/tut.JPG";
document.body.appendChild(image);
var image2 = new Image;
image2.src="Images/bullets.jpg"
document.body.appendChild(image2);
0 michael walker · March 20, 2015
now it does work i see the problem in your code:

the code is:
var x = new Image; - the word "Image" next to new must be with a capital letter 

x.src="(your path)";

document.body.appendChild(x);

I have tested the code with numerous uploads of images on Dreamweaver CS6 and it works.

i hope this helps :)
0 william appiah-dankwah · March 20, 2015
:'( yeah thanks walker, man. why append child though?
0 william appiah-dankwah · March 21, 2015
:'( the variable only works if you call it image why?
0 william appiah-dankwah · March 21, 2015
well i had been looking at that code till early hours in the morning re writing the code and checking for mistakes. i find that strange the mistakes have been found this morning :ermm::ermm: 
0 william appiah-dankwah · March 21, 2015
Trying to work out append child i understand its the last child node but i just want to clarify this in this code.:'(:(

function Yellow(){

// the Parent node is image

var image = new Image;

//the last child is image.src and thats what is being appended in this code

image.src = "pic/photo-1.JPG";

document.body.appendChild(image);
}

is that correct? :ninja:










0 michael walker · March 23, 2015
Yes that is my understanding of it as well :) sorry weekend super busy XD

Javascript

106,985 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators