diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js
index f017fd846b1..be8d0a5996f 100644
--- a/src/librustdoc/html/static/main.js
+++ b/src/librustdoc/html/static/main.js
@@ -1281,7 +1281,7 @@ function hideThemeButtonState() {
if (currentType) {
currentType = currentType.getElementsByClassName("rust")[0];
if (currentType) {
- currentType.classList.forEach(function(item) {
+ onEachLazy(currentType.classList, function(item) {
if (item !== "main") {
className = item;
return true;