-3

The problem: doesnt output an image. image name (1).jpg up to (42).jpg

<script type=text/javascript>
  var i=1;
    while (i<=42) {
      document.write("<div style=min-height:200px; onmouseover=\"innerHTML=\'<img style=width:800px; src=(");
      document.write(i);
      document.write(").jpg/>\'\">Hover</div>" + i);
      i++;
  }
</script>

Additional info:

  • tried this locally with wamp and it worked fine
Alex
  • 8,774
  • 1
  • 34
  • 42
  • 1
    do you get any javascript errors? – jackJoe Oct 01 '11 at 13:11
  • 2
    How are you running this when it does *not* work, as opposed to wamp? Are the images also available in the not-working case? – pimvdb Oct 01 '11 at 13:12
  • What browser are you working? I just tried sticking this in the javascript console in google chrome and it works just fine ... – Foo Bah Oct 01 '11 at 13:18
  • When you've figured this out, you might want to [refactor your code to avoid `document.write`](http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice) – James Thorpe Nov 01 '16 at 14:42

1 Answers1

0

This is the result of the above code:

<div style="min-height:200px;" onmouseover="innerHTML='&lt;img style=width:800px; src=(1).jpg/&gt;'"><img style="width:800px;" src="(1).jpg/"></div>

What do you mean that is not working? If you mean that does not display the images after the hover then you have to correct the image path.

Look if the images are located in the same folder with the page that run that code, otherwhise correct the path.

Avag Sargsyan
  • 2,149
  • 3
  • 24
  • 31
KodeFor.Me
  • 11,719
  • 19
  • 82
  • 154