To write a code inside DIV layer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blobb
    New Member
    • Apr 2007
    • 12

    To write a code inside DIV layer

    hi all,
    i have my header, where i do the following code to call a random image from the site folder:

    Code:
    <script language="javascript" type="text/javascript"> 
    
    p=65*Math.random(); 
    d=parseInt(p); 
    document.write ("<table background='../pics/site/"+d+".jpg'></table>"); 
    
    </script>
    but now i want to replace a table with a DIV, to make the pageload faster.

    so i have tried the following:

    Code:
    document.write ("<div style="background: url('../pics/site/"+d+".jpg')"></div>")
    but this is not working.
    can You please help me, how to write the correct code?
    thx.
  • merseyside
    New Member
    • Mar 2007
    • 48

    #2
    Code:
    document.write ("<div style="background: url('../pics/site/"+d+".jpg')"></div>")
    Is the above a direct copy from your script? If so the quotes around the style need to be escaped, see below.

    Code:
    document.write ("<div style=\"background: url('../pics/site/"+d+".jpg')\"></div>")
    You may also need to explicitly set the width and height of the div in the style attribute. If still no luck, change the style property background to background-image keeping the value the same. The property background usually colour, image url and position values to be present.

    Comment

    • blobb
      New Member
      • Apr 2007
      • 12

      #3
      no, this did not help.

      document.write ("<div style=\"backgro und-image: url('../pics/site/"+d+".jpg') \"></div>") - this is also not helping..

      can You please suggest, how to write in the correct height and width? then i'll try again.

      Comment

      • merseyside
        New Member
        • Mar 2007
        • 48

        #4
        Originally posted by blobb
        no, this did not help.

        document.write ("<div style=\"backgro und-image: url('../pics/site/"+d+".jpg') \"></div>") - this is also not helping..

        can You please suggest, how to write in the correct height and width? then i'll try again.
        Code:
        document.write ("<div style=\"background-image:url('../pics/site/"+d+".jpg');width:[I]n[/I]px;height:[I]m[/I]px;border:1px solid #000000;\"></div>")
        Added a border to make sure the div is the expected size. If the image still isn't appearing then the page in the url may be incorrect (obviously once you're happy the image is appearing get rid of the border property). Do all the images have the same dimensions? How are more images added? Is this in a HTML page or a script?

        Comment

        • blobb
          New Member
          • Apr 2007
          • 12

          #5
          thanx a lot!!!

          Comment

          Working...