title: Hiding / Setting display none on element using parentElement.getElementsByClassName
body: <p>I am trying to hide a button that creates a new element after being clicked (to then be replaced by a delete), but i seem to be unable to change the display to &quot;none&quot; when i try to target the same element using the parentElement and then getting the elements by classname.</p>
  <p>The reason i want to do it this way is to make the other element visible the same way, but it's outside of the scope of the issue i'm having right now.</p>
  <p>I entered an example of my issue below.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let template = '&lt;div&gt;&lt;button onclick="createNewElement(this)" class="js-create-button"&gt;+&lt;/button&gt; &lt;/div&gt;'
  
  
  function createNewElement(e){
    e.parentElement.parentElement.innerHTML += template; // Creating new button using the template
    let a = document.getElementsByClassName("js-create-button")[0];  // Getting the element using document
    let b = e.parentElement.getElementsByClassName("js-create-button")[0];  // Getting the element using a parent element (this is the line that's causing issues)
    console.log(a);  // Both logs return the correct element, but only the first one works when i change the styling
    console.log(b);
    a.style.background = "red";
    b.style.background = "blue";
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
    
  &lt;div&gt;
    &lt;div&gt;    
      &lt;button onclick="createNewElement(this)" class="js-create-button"&gt;+
      &lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>In the example i changed the style to make it easier to see what's not working. The style should turn to blue, instead of red, and that goes for all the created elements after the first one too.</p>
  <p>It somehow seems like the element that's returned is a &quot;copy&quot; of the original, so changing it does nothing.</p>