Reputation: 77
I have this code:
function getImage(imgPath,override){
image=new Image();
image.src=imgPath;
document.getElementById('imgboxDavanti').appendChild(image);
}
and the HTML that calls this function is:
<a href='#' onclick="getImage('immagini/giaccasaccobacino/1petto/beige.png','true')">
this is the div where i would put the image
<div id="imgbox">
<div id="imgboxDavanti">IMAGE HERE</div>
<div id="imgboxDietro"></div>
</div>
but I don't display the image (and if I pass a wrong path as an argument, I see the typical "image not found" icon). What's the problem?
Upvotes: 0
Views: 79
Reputation:
And if you modify to this? (there is no obvious error in your code, but check mainly what error message says if any..);
function getImage(imgPath,override){
image = document.createElement('img');
image.onload = function() {
document.getElementById('imgboxDavanti').appendChild(image);
}
image.onerror = function(e) {
console.log(e);
alert('Error occurred, see console for details.');
}
image.src = imgPath;
}
Upvotes: 1
Reputation: 2103
Try with create element for <input type="image" src="picture.gif" />
function getImage(imgPath,override){
image=document.createElement('INPUT');
image.type="image";
image.src=imgPath;
document.getElementById('imgboxDavanti').appendChild(image);
}
Upvotes: 1