Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
91
rated 0 times [  96] [ 5]  / answers: 1 / hits: 33183  / 11 Years ago, mon, november 18, 2013, 12:00:00

I've looked at many other posts and I think I'm using the exact syntax suggested. However, I'm not getting the images to show up. I have a jsfiddle. Is it a jsfiddle issue? It's also not working on a website I'm working on.



<div id=divtest>Hello</div>
<img id=imgtest />
<img id=imgreal src=http://www.premiumbeat.com/blog/wpcontent/uploads/2012/12/free.jpeg />

var string = url('http://www.premiumbeat.com/blog/wpcontent/uploads/2012/12/free.jpeg');
alert(string)
document.getElementByID(divtest).style.backgroundImage = string;
document.getElementByID(imgtest).src = string;

More From » image

 Answers
20

Two minor problems:




  1. getElementByID is not a function; getElementById is.


  2. The format for a url is different for an image source and a background image. Try this:

    var string = 'http://www.premiumbeat.com/blog/wp-content/uploads/2012/12/free.jpeg';
    document.getElementById(divtest).style.backgroundImage = url(' + string + ');
    document.getElementById(imgtest).src = string;



[#74213] Sunday, November 17, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;