how to put an image over a value using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yiskas
    New Member
    • Aug 2011
    • 11

    #1

    how to put an image over a value using javascript

    i'm working on a minesweeper game and i don't know how to replace an image (=any button was clicked)by the value suppose to be under it.
    (i have already all the functionality of bombs and neighbors and 10*10 images of buttons - but i can display this or this- not they both at once and this is another question - how to put the numbers and bombs under the button images...)
    i'll be glad to get some help,thanks in advance.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    This will change the image with ID Pos0905 with a new image. This will probably use the onclick event of the image. Do your checks and then replace with the appropriate image.
    Code:
    document.getElementByID("Pos0905").src = "bomb.png";
    You can overlap elements by using absolute or fixed positioning. But in this case. I would just suggest creating images for the 9 numbers, then you don't have to overlap elements, you just have to change the source of the image.

    Comment

    • yiskas
      New Member
      • Aug 2011
      • 11

      #3
      Thanks,
      But i realy don't know what is "Pos0905".

      -I tried doing this: document.getEle mentByID("bomb" ).src = "bomb.png";
      and i get an error massage:"Uncaug ht TypeError: Cnnot read property 'src' of null"

      Why is that?

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        This is sample code, it's not meant to just work because I don't know your setup. In the example, Pos0905 is the ID of an image. A name I made up to identify the different squares in an array of images. The error is probably because you don't have an element with the id bomb that has an attribute src.

        If you're having trouble understanding the code, you should look into a javascript tutorial before you start the project.

        Comment

        • yiskas
          New Member
          • Aug 2011
          • 11

          #5
          thank you thank you, you were very helpful and gave me ways i can think of.תודה

          Comment

          Working...