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 1
Oldest  Newest  Rating
0 william appiah-dankwah · November 29, 2016
<head>
<script type="text/javascript">
face= new Image(120,120);
face.src="photo-1.JPG";
head= new Image(120,120);
head.src="photo-2.JPG";
</script>
</head>
<body>
<a href="#"onmouseover="javascript:document.face.src='photo-1.JPG'"
onmouseout="javascript:document.head.src='photo-2.JPG'">
<img src="photo-2.JPG" name="head" border="1"></a>
</body>


this code is meant to turn into another picture when the mouse hovers over it but does not work for me does anyone know why?
0 william appiah-dankwah · April 15, 2015
does anyone know why the loop is not working for the code that i have posted?
0 william appiah-dankwah · April 14, 2015
worked the append child out need to re-read how do you use pop(); to remove image thats what i am working on right now
0 michael walker · March 23, 2015
Yes that is my understanding of it as well :) sorry weekend super busy XD
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 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
:'( the variable only works if you call it image why?
0 william appiah-dankwah · March 20, 2015
:'( yeah thanks walker, man. why append child though?
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 :)

Javascript

106,974 followers
About

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

Links
Moderators