How to add simple js to theme </body>

I am trying to add simple javascript to in CSS/HTML edit in Themes.

Effectively the ability to click buttons to expand content with addEventListener

var coll = document.getElementsByClassName("collapsible");
var i;

for (i = 0; i < coll.length; i++) {
  coll[i].addEventListener("click", function() {
    var content = this.nextElementSibling;
    if ( === "block") { = "none";
    } else { = "block";

However, this script doesn’t seem to appear in the source code.

Any help?