Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: image

  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    image

    Hi, im trying to insert star images, from one to five stars after a film name using the code below. However only one star ever appears...so what is wrong with my for loop?

    var ImgElm=document.createElement("img")
    ImgElm.setAttribute("alt","ystar4");
    ImgElm.setAttribute("src","ystar4.gif");
    for(var i=1; i<=Ratings; i++) {

    titleContainer.appendChild(ImgElm);
    }
    titleContainer.appendChild(newline);

  • #2
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    A node can only be in one place at a time, so it is removed from the old position when inserted into the new one. You need to clone the node if you want more than one of it. Have a look here: Node.cloneNode for more information about how to do that.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •