title: How do you assign a JavaScript 'onclick' attribute dynamically?
body: <p>I'm creating a button dynamically using JavaScript and at the same time assigning attributes such as 'ID', 'type' etc and also 'onclick' in order to trigger a function.</p>
  
  <p>All works fine apart from the assignment of the 'onclick'. When clicked, the button is not triggering the function as it is supposed to. the function I'm trying to run is 'navigate(-1)' as seen below.</p>
  
  <p>Where am I going wrong?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>function loadNavigation() {
    var backButton;
    backButton = document.createElement('input');
    backButton.ID = 'backButton';
    backButton.type = 'button';
    backButton.value='Back';
    backButton.onclick = 'navigate(-1)';
    document.body.appendChild(backButton);
  }
  </code></pre>