Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highway not working with DOM elements rendered by javascript #117

Open
Rinmawia opened this issue Jan 30, 2023 · 1 comment
Open

Highway not working with DOM elements rendered by javascript #117

Rinmawia opened this issue Jan 30, 2023 · 1 comment

Comments

@Rinmawia
Copy link

Rinmawia commented Jan 30, 2023

So, I have a list of cards that is rendered using Javascript, and every cards has it's link, Highway doesn't seem to work on these elements. Is there anyway to fix this?

cardContainer.innerHTML += `
                    <a class="card" href="/${card.url}" draggable="false">
                        <h1 class="title"><span>${card.title}</span></h1>
                        <p class="description"><span>${card.description}</span></p>
                        <video class="card-video" muted loop>
                          <source src="${card.image}" type="video/webm">
                        </video>
                    </a>
                `;
@Rinmawia Rinmawia changed the title Highway not working with DOM elements rendered by javascripts Highway not working with DOM elements rendered by javascript Jan 30, 2023
@stefbowerman
Copy link

For links rendered via JS, you have to explicitly attach them using attach on your Highway instance. This would look something like this:

const highway = new Highway.Core({...})

cardContainer.innerHTML += `
                    <a class="card" href="/${card.url}" draggable="false">
                        <h1 class="title"><span>${card.title}</span></h1>
                        <p class="description"><span>${card.description}</span></p>
                        <video class="card-video" muted loop>
                          <source src="${card.image}" type="video/webm">
                        </video>
                    </a>
                `;

highway.attach(document.querySelectorAll('a.card'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants