0

I'm wondering how to implement initialization via JavaScript similar to Ken Wheeler's Slick Carousel. Using jQuery you can select an element like this: $('.carousel-element').slick();.

Is there any way do something similar using JavaScript? For example if I have a variable that holds an element, can I use that to call a custom function?

const myElement = document.getElementById('example-1');

myElement.customFunction();

Thank you in advance! I was having a lot of trouble figuring out how to word this, so if anyone knows what this technique is called that will help as well.

Rob
  • 47
  • 1
  • 6
  • Sound like a [x/y](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) problem. Can you give a example of `customFunction()` to see why you would do this? – 0stone0 Dec 08 '22 at 15:46
  • _"Is there any way do something similar using JavaScript"_ jQuery ___is___ JavaScript! – phuzi Dec 08 '22 at 15:47
  • You would have to add a function to the `Element` prototype that you could then call on any element. I'm not sure whether it would make sense to do this though, it depends upon your use-case. – phuzi Dec 08 '22 at 15:48

0 Answers0