Testing shows that the newElement() function has no trouble there, and the error occurs on that line, so it has to be the assignment. Why could that be?

Could it be that the container variable should not reach out beyond the function to make changes to a similar variable at a different scope?

elsewhere:

var container = slideContainer(parameters.container, display);

There are a lot of different container variables at different scopes, so it seems that one is trying to clobber the other.Let's ensure that the container variable in the slideContainer remains in there: