I'm not sure the toLowerCase is needed.

For a typesafe and unspoofable alternative to checking element types, you can also use container.constructor == HTMLBodyElement.