question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Glide warn]: Root element must be a existing Html node TypeError: this.root is undefined [ SOLVED ]

See original GitHub issue

I have one slider included in two page like : index.html, about.html

Two pages have same slider index.html : init slider one time

but in about.html init two time on two slider with same class

[Glide warn]: Root element must be a existing Html node 
TypeError: this.root is undefined
import Glide from '@glidejs/glide'

window.addEventListener('load', () => {

    
  const customers = new Glide(".view-customers", {
        type: "carousel",
        startAt: 0,
        perView: 6,
        direction: "rtl",
        autoplay: "10000",
        breakpoints: {
            1024: {
              perView: 4
            },
            760: {
              perView: 3
            },
            480: {
                perView: 2
            }
        }
    });
    
    customers.mount();
})

html:

<div class="view-customers">
                                <div data-glide-el="controls"></div>
                                <div class="glide__track" data-glide-el="track">
                                    <ul class="glide__slides">
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/ISO.png" alt="" /></div>
                                        </li>
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/ISO.png" alt="" /></div>
                                        </li>
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/ISO.png" alt="" /></div>
                                        </li>
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/ISO.png" alt="" /></div>
                                        </li>
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/food.png" alt="" /></div>
                                        </li>
                                        <li class="glide__slide">
                                            <div class="customer-img text-center"><img src="images/partners.png" alt="" /></div>
                                        </li>
                                    </ul>
                                </div>
                            </div>

what’s my mistake ? 😢

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
jedrzejchalubekcommented, Nov 22, 2018

Glide will not initialize for you multiple instances when you passing a selector string as parameters. It will see that this is a string and make a single querySelector call.

To initialize multiple sliders with same selector you have to query collection of HTMLElements by yourself and initialize glide on each one individually (in a simple loop).

var sliders = document.querySelectorAll('.glide');

for (var i = 0; i < sliders.length; i++) {
  var glide = new Glide(sliders[i], {
    // options
  });

  glide.mount()
}
1reaction
pyxalwebcommented, Mar 29, 2022

Glide will not initialize for you multiple instances when you passing a selector string as parameters. It will see that this is a string and make a single querySelector call.

To initialize multiple sliders with same selector you have to query collection of HTMLElements by yourself and initialize glide on each one individually (in a simple loop).

Here is the same solution with forEach instead of the older for loop:

document.querySelectorAll('.glide').forEach((element) => {
    let glideInstance = new Glide(element, {
        // options
    })
    glideInstance.mount()
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Glide warn]: Root element must be a existing Html node ...
It will see that this is a string and make a single querySelector call. To initialize multiple sliders with same selector you have...
Read more >
Rails 6 GlideJS carousel issues (without jquery) - Reddit
... dev tools in firefox I am seeing [Glide warn]: Root element must be a existing Html node / Uncaught TypeError: this.root is...
Read more >
typescript-cheatsheet - GitHub Pages
A set of TypeScript related notes used for quick reference. The cheatsheet contains references to types, classes, decorators, and many other TypeScript ...
Read more >
jQuery API Documentation
jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax ......
Read more >
SyntaxError: missing ; before statement - JavaScript | MDN
You need to provide a semicolon, so that JavaScript can parse the source code correctly. Message. SyntaxError: Expected ';' (Edge) SyntaxError: missing ;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found