-2

I am trying to place an image inside a div.

function pleaseW(){
    $('#info').html("Please wait ...");                         //1 this works
    $('#info').html("<img id='busy01' src='busy01.gif' />");    //2 doesn't work
    $('#info').append("<img id='busy01' src='busy01.gif' />");  //3 doesn't work
    $('#info').prepend("<img id='busy01' src='busy01.gif' />"); //4 doesn't work
}

The image called busy01.gif is in the same folder as in the current file. The problem is that lines 2, 3, and 4 do not put an image in the div.

If I put the html directly into the page, the image shows. There has to be some unrelated problem going on with the page, as this Javascript/jQuery is perfectly valid.

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
Alegro
  • 6,294
  • 17
  • 47
  • 73

3 Answers3

1

Try

$('#info').html("<img id='busy01' style='width:100px; height:100px;' src='busy01.gif' />");  
ATOzTOA
  • 30,490
  • 20
  • 83
  • 113
0

From the Author:

I moved the script from the bottom of the page to the head portion of the html. Now it works.

Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
-1

This seems to be an archaic issue with browser compatibility, not a JavaScript issue.

Each of these lines should show an image:

function pleaseW(){
    $('#info').html("<img id='busy01' src='busy01.gif' />");    //2 doesn't work
    $('#info').append("<img id='busy01' src='busy01.gif' />");  //3 doesn't work
    $('#info').prepend("<img id='busy01' src='busy01.gif' />"); //4 doesn't work
}
Eric Leschinski
  • 123,728
  • 82
  • 382
  • 321
crush
  • 15,889
  • 8
  • 54
  • 95
  • 1
    HTML 4 spec? What is this 1990 – crush Jan 11 '13 at 14:07
  • "By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39)" – Rene Pot Jan 11 '13 at 14:08
  • Then there is absolutely nothing wrong with that line of Javascript, and it should work. – crush Jan 11 '13 at 14:09
  • @crush Here's a reference to the HTML5 spec: http://stackoverflow.com/questions/4577092/is-it-acceptable-to-use-single-quotes-around-values-in-html-attributes, as you can see they are valid. Ugly, but valid. – Rory McCrossan Jan 11 '13 at 14:09
  • correct. It should work. Thus my question comment on the question – Rene Pot Jan 11 '13 at 14:10
  • @RoryMcCrossan: you should link directly to the answer instead... http://stackoverflow.com/a/4577109/75642 – Robert Koritnik Jan 11 '13 at 14:11
  • Seems this is actually an archaic issue with browser compatibility, not a spec issue. – crush Jan 11 '13 at 14:12
  • 1
    @RobertKoritnik Sorry, I meant to link to the HTML5 spec itself. I pasted the wrong link – Rory McCrossan Jan 11 '13 at 14:13