Ok, that makes sense. I have duplicate menu items on the same page so the ids not being unique sounds like the culprit.
Now that I understand the issue better I’ll use regex to make object selection by class more robust.
Thanks again (and for the regex)!