title: Change title attribute of dynamically generated html element for tooltip
body: <p>I have a dynamically generated HTML element that includes a title attribute which appears in a tooltip when hovering, like:</p>
  
  <pre><code>&lt;div title="tooltip text" class="classname" id="identifier"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>I would like to change the contents of the title attribute using javascript code set to run as part of the HTML render. Currently, my code is as follows:</p>
  
  <pre><code>var changeTooltip = function(){
       var TooltipElement = document.getElementsByClassName("classname");
       if (TooltipElement.title = "tooltip text"){
           TooltipElement.title = "new message";
       };
  };
  
  window.onload = changeTooltip();
  </code></pre>
  
  <p>This code leaves the original string in the div's title attribute once the page renders fully. Can anyone explain why, and possibly show the correct way? Note that I must use JS, I cannot use JQuery.</p>