Backfound-image one, Should be simple but most needed!!

Discussion in 'JavaScript' started by progfrog, May 14, 2008.

  1. #1
    hi guys,
    i'm trying to change the backgroung-image of an object using a reguler js function that i wrote-

    this is the code, but for some reason , it doesn't work:

    
       tli.style.background="background-image: url('images/p.jpg') no-repeat";
    
    
    
    
    Code (markup):
    tli is an object taht contain some <p>that i would like to change her background , but the code i wrote doesn't work- Can u help me??


    thanx a lot
    progfrog
     
    progfrog, May 14, 2008 IP
  2. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #2
    ok, in javascript, for doing css styles, for example, the "background-image" property, you must remove the hyphen and capitalize the second letter, like this, "backgroundImage". Next, javscript is an object oriented language, so you do objects and attributes. You need to make your code look like this.

    tli.style.backgroundImage = "url('images/p.jpg') no-repeat";
    Code (markup):
    See, it will set the "background-image" property of object "tli" to "url('img... bla bla bla"

    :)
     
    crath, May 14, 2008 IP
  3. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    HI man, It doesn't work for me also.. can u try it your self and tell me what did u managed to do?

    thanx again,
    progfrog
     
    progfrog, May 15, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    did you first do
     var tli = document.getElementById("objectID");
    Code (markup):
    first?
     
    crath, May 15, 2008 IP
  5. progfrog

    progfrog Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yes, i did but is still doesn't work.. us there anything else that can make it work?

    sorry for posting to u a week later..
     
    progfrog, May 21, 2008 IP
  6. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #6
    are you getting any errors or warnings?
     
    crath, May 21, 2008 IP