title: How to pass a variable to the style property in javascript?
body: <p>I'm sorry if the question is phrased with the incorrect terminology. </p>
  
  <p>Basically I want to specify what style I want to change in a function by passing it a variable.</p>
  
  <pre><code>function styleChanger(ele, styleProp, x){
        ele.style.styleProp = x + "px";
  }
  
  var box = document.getElementById("box");
  var height = 100;
  var width = 100;
  var top = 500;
  var styleProp = [height,width,top];
  
  styleChanger(box, styleProp[0], height);
  styleChanger(box, styleProp[1], width);
  styleChanger(box, styleProp[2], top); 
  </code></pre>
  
  <p>I want to do this but its not possible, is there a way? </p>