I have found it useful to use the HTML block in Elementor and paste the code there unless a more elegant solution is needed. The block can be added just after the accordion and the JavaScript can be wrapped in a <script> tag. This will ensure that the code only executes on the page where it is needed.