JavaScript An efficient way of using getElementByID multiple times with Object literal?

I'm a beginner at javascript and just getting started with working with the DOM. After grabbing a bunch of spans with different ID names at several different places and grabbing the data from an object literal, it seemed to start getting redundant. Isn't there a better way of writing this? I'm also learning functions but not really sure how to relate it together. Here's the JSfiddle for easier viewing. https://jsfiddle.net/q5366wzb/

HTML:

<fieldset id="candidates">
   <legend>Candidates</legend>
   <div>
   <label for="cand1">Candidate 1</label>
   <span class="candidate" id="cand1"></span>
   <span class="party" id="party1"></span>
</div>

<div>
  <label for="cand2">Candidate 2</label>
  <span class="candidate" id="cand2"></span>
  <span class="party" id="party2"></span>
 </div>

 <div>
  <label for="cand3">Candidate 3</label>
  <span class="candidate" id="cand3"></span>
  <span class="party" id="party3"></span>
 </div>
 </fieldset>

  <fieldset id="statistics">
  <div>
  <h2>Results for Candidate 1</h2>
   <div id="candidateName1"></div>
   <label for="cand1pct">Percentage</label>
   <output id="cand1pct"></output>
  </div>
  <div>
  <h2>Results for Candidate 2</h2>
  <div id="candidateName2"></div>
  <label for="cand2pct">Percentage</label>
  <output id="cand2pct"></output>
  </div>
  <div>
  <h2>Results for Candidate 3</h2>
  <div id="candidateName3"></div>
  <label for="cand3pct">Percentage</label>
  <output id="cand3pct"></output>
  </div>
  </fieldset>

JS

var votingData = {
  candidates: [{
  name: "Harry S. Truman",
  party: "Democratic"
},
{
  name: "Thomas E. Dewey",
  party: "Republican"
},
{
  name: "Strom Thurmond",
  party: "Dixiecrat"
}]
};


 document.getElementById("cand1").innerHTML = 
 votingData.candidates[0].name;
 document.getElementById("candidateName1").innerHTML = 
 votingData.candidates[0].name;
 document.getElementById("party1").innerHTML = 
 votingData.candidates[0].party;

 document.getElementById("cand2").innerHTML = 
 votingData.candidates[1].name;
 document.getElementById("candidateName2").innerHTML = 
 votingData.candidates[1].name;
 document.getElementById("party2").innerHTML = 
 votingData.candidates[1].party;

 document.getElementById("cand3").innerHTML = 
 votingData.candidates[2].name;
 document.getElementById("candidateName3").innerHTML = 
 votingData.candidates[2].name;
 document.getElementById("party3").innerHTML = 
 votingData.candidates[2].party;
Answer:1

React's documentation recommends passing functions as properties to child components in order to alter state variables of the parent. I'm finding this design to be a little cluttered on parents that ...

React's documentation recommends passing functions as properties to child components in order to alter state variables of the parent. I'm finding this design to be a little cluttered on parents that ...

I have a simple application which need to render 2 components dynamically. Component A - needs to have onClick event. Component B - needs to have onChange event. How is it possible to dynamically ...

I have a simple application which need to render 2 components dynamically. Component A - needs to have onClick event. Component B - needs to have onChange event. How is it possible to dynamically ...

  1. working with dynamic crop models
  2. working with dynamic objects c#
  3. working with dynamic crop models pdf
  4. working with dynamic c#
  5. working with dynamic table in selenium
  6. working with dynamic inventory ansible
  7. working with dynamic blocks in autocad
  8. working with dynamic inventory
  9. working with dynamic web tables
  10. working with dynamic text
  11. working with dynamic sql
  12. working with dynamic arrays in vba
  13. working with dynamic json
  14. working with dynamic blocks
  15. working with dynamic
  16. c# working with dynamic json
  17. c# working with dynamic type
  18. c++ working with dynamic memory
  19. working dynamic synonym
  20. working dynamic web shooter

It's pretty simple: Object.entries is supposed to produce and Array of key, value pairs.. As such, I would expected this code to destructure [{ id: 1, name: "christian" },{ id : 2, name: "...

It's pretty simple: Object.entries is supposed to produce and Array of key, value pairs.. As such, I would expected this code to destructure [{ id: 1, name: "christian" },{ id : 2, name: "...

  1. javascript array destructuring assignment
  2. javascript array destructuring performance
  3. javascript array destructuring last element
  4. javascript array destructuring rest
  5. javascript array destructuring ignore first
  6. javascript array destructuring first element
  7. javascript array destructuring function arguments
  8. javascript array destructuring default value
  9. javascript array destructuring
  10. javascript array destructuring last
  11. javascript array destructuring mdn
  12. javascript array destructuring map
  13. javascript destructuring array of objects
  14. use array destructuring javascript
  15. array destructuring javascript example
  16. array destructuring javascript es6
  17. javascript destructuring nested array
  18. javascript destructuring array index
  19. javascript destructuring array into object
  20. javascript destructuring swap array

I have a situation very similar to this: http://jsfiddle.net/8kbx4/ Basically, it is a table with scrolling which doesn't show all the columns at the same time. The browsers (at least, FF and Chrome)...

I have a situation very similar to this: http://jsfiddle.net/8kbx4/ Basically, it is a table with scrolling which doesn't show all the columns at the same time. The browsers (at least, FF and Chrome)...