Jump to content

Need help with document.getElementById for multiple items ?

Recommended Posts

Hello & Thanks ,

var player1Score = 10;

var player2Score = 20;

document.getElementById('keepScore').innerHTML = ' player2Score = ' + player2Score;


I want to be able to display several items on one line with the above code or preferably something that works .

Pls , how can I do this .



Link to post
Share on other sites

I couldn't get the crazy thing working so I did this instead:

<table style="width:100%">
    <td width="10%"> totalScore = </td> <td id="totalScore" width="5%"> </td>
    <td width="8%"></td>
    <td width="10%"> oops! = </td> <td id="oopsScore" width="5%"> </td>
    <td width="8%"></td>
    <td width="10%"> totalHits = </td> <td id="totalHits" width="5%"> </td>
    <td width="8%"></td>
    <td width="10%"> totalShots = </td> <td id="totalShots" width="5%"> </td>	


Link to post
Share on other sites

Why not use array

<!DOCTYPE html>

<p id="demo"></p>

var items = [["player1Score", 10],["player2Score", 20]];
//to add extra item
items[2]=["player3Score", 30];
var join="";


join+= items[i][0]+"= "+items[i][1];
join+=", ";

document.getElementById("demo").innerHTML =join;



  • Like 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...