An element is not written to a variable, and since there are several elements, an array must be formed, but it is formed empty.
console.log(opengal.length, opengal[0]); console.log($(".expand").length, $(".expand")[0]); console.log(zoombox.length, zoombox[0]) <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> var zoombox = $("<div class='popup'></div>"); var opengal = $(".expand"); </script> <div class="expand"></div> <div class="expand"></div> <div class="expand"></div> <div class="expand"></div> <div class="expand"></div> opengal should be an array of 5 buttons, but for some reason it is empty.
The other variables are fine.