Make sure you initialize the masonry properly as the code is only working when some event occurred (resize event in your case).
Masonry works on a container grid element with a group of child items.
<div class="grid">
<div class="grid-item">...</div>
<div class="grid-item grid-item--width2">...</div>
<div class="grid-item">...</div>
...
</div>
Initialize with jQuery
You can use Masonry as a jQuery plugin: $('selector').masonry().
$('.grid').masonry({
// options
itemSelector: '.grid-item',
columnWidth: 200
});
Source: https://masonry.desandro.com/
Edit: Please make sure you are passing strings (in the options) if you want to use a selector as the masonry code will only run document.querySelector
for a string.![enter image description here]()
Otherwise, the value is used as it is.