Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
I got error adding masonry to my alpinejs app

In Laravel 8 / livewire 2.5 / alpinejs 3.4.2 I try to add masonry for listing of images, but initing it by ID or by classname I got error :

Uncaught TypeError: document.getElementById(...).masonry is not a function
at Proxy.onHostelsGalleyViewPageComponentInit

In blade file :

<div class="frontend_page_container" x-data="hostelsGalleyViewPageComponent()" x-init="[onHostelsGalleyViewPageComponentInit() ]" id="hostels_gallery_page_container">

    <section class="relative py-10">
        <div class="container mx-auto px-4">

            @if(count($hostelsDataRows) > 0)
            <div class="main_gallery__blocks" id="main_gallery__blocks">
                @foreach($hostelsDataRows as $nextHostel)
                @livewire('hostel.hostel-gallery-item', ['nextHostel' => $nextHostel, 'loop_index'=>
                $loop->index])
                @endforeach
            </div>
            @endif

        </div>
    </section>

    <script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>

    <script>

        function hostelsGalleyViewPageComponent() {
            return {
                onHostelsGalleyViewPageComponentInit: function () {
                    console.log('onHostelsGalleyViewPageComponentInit::')

                    // var $grid = document.getElementsByClassName('main_gallery__blocks').masonry({ // THIS LINE RAISE the same error
                    var $grid = document.getElementById('main_gallery__blocks').masonry({
                        itemSelector: '.main_gallery__block',
                        columnWidth: '.main_gallery__block',
                        percentPosition: true
                    })

                },

            }
        } // function hostelsGalleyViewPageComponent() {

    </script>

</div>

Which way is correct ?

Thanks!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!