Yep, your code looks OK.
Is there a way to keep the accordion functionality, but also auto scroll to the main menu item that was clicked so that no part of the expanded sub menu section gets pushed off screen?
On theory auto scrolling is not a problem (in most cases), but it’s not producing a good user experience either and that’s why it’s not used in similar accordion scripts.