Perhaps you can do this with :target
mdn instead of with javascript?
section:not(:target) :not(:first-child) { display: none; }
<section id="parent1">
<h1><a href="#parent1">Parent1</a></h1>
<ul class="child">
<li>
Some content
</li>
</ul>
</section>
<section id="parent2">
<h1><a href="#parent2">Parent2</a></h1>
<ul class="child">
<li>
Some content
</li>
</ul>
</section>
<section id="parent3">
<h1><a href="#parent3">Parent3</a></h1>
<ul class="child">
<li>
Some content
</li>
</ul>
</section>