// Change the text of the button to ‘Hide code’

document.querySelector('#' + parentElement + ‘.code-show-button’).value = ”Hide code”;

// Add the class ‘open’ to our main parent element

parentElementDiv.classList.add(‘open’);

Now that we have created our JavaScript for when we want to open up our new div, we need to write the other side of the if statement, responsible for getting rid of the element once the user clicks the ‘hide code’ button.

Fortunately, this is a bit simpler than the code to create the div in the first place.

All we really need to do here is provide a reference to our newly created element, then remove it from the parent node, before changing the button text back to ‘Show code’ and removing the ‘open’ class from the main div.

Once again, let’s look at the code for this before stepping through this final part of the puzzle.