SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Scary's On The Wall
    Join Date
    Apr 2003
    Location
    PA
    Posts
    518
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getElementById failing

    For some reason, fighter_health_bar is showing up null when I try to set its width...

    Code:
    <html>
    <head>
    </head>
    <body>
    
    <script>
    
                function update_health_bar(fighter, percent) {
    
                    var fighter_health_bar = document.getElementById("attackerHealth");
                    fighter_health_percent = percent + "%";
                    fighter_health_bar.SetAttribute("width", fighter_health_percent);
    
                }
    
    update_health_bar('attacker', 85);
    
    </script>
    
                <table border="0" cellpadding="0" cellspacing="0" width="250">
                    <tr>
                        <th colspan="2">Attacker</th>
                    </tr>
                    <tr>
                        <td id="attackerHealth" width="100%" height="15" bgcolor="red" align="center"></td>
                        <td width="*"></td>
                    </tr>
                </table>
    
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Nov 2003
    Location
    Malmoe, Sweden
    Posts
    265
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thatīs not very strange. When you make the call to the function the element is not yet loaded. Computers read line by line.


Bookmarks

Posting Permissions

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