Check that the elements have already loaded with the appropriate IDs. If the code runs before the elements appear in the DOM, it won’t find the elements.

To test create a debug action that will run the code after the page has loaded. Make a button that runs the code.