867 votes
0 answers
javascript - Slick Slider doesn't work with shopify dawn's product recommendation section
Solution:
Your code is probably not working because the DOM elements are not yet created when you look for them. Run your code after the window is fully loaded by using the window:
- load (https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event) event
fired when the whole page has loaded, including all dependent resources such as stylesheets, scripts, iframes, and images.
// vanilla JS
window.addEventListener("load", (event) => {});
window.onload = (event) => {};
// JQuery
$(window).on('load', function() { })
- or DOMContentLoaded (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) event
fired as soon as the page DOM has been loaded, without waiting for resources to finish loading
// vanilla JS
window.addEventListener('DOMContentLoaded', (event) => {});
window.onDOMContentLoaded = (event) => { };
// JQuery
$(window).on('ready', function() { })
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
624 @shopify/shopify-api nodejs - Set permanent access token for private app installed on only one store
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.