Uncaught TypeError | Is Not A Function | Solution
Aug 15, 2023
Uncaught TypeError | Is Not A Function | Solution
Have you encountered an error like: - Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel is not a function - slickSlider is not a function And this error may not be in every page of your website. It will be at some pages. I have taken a slider as example and created two pages. At one page I have initialized the slider and other page only has simple text. In this tutorial we will see this error and will solve it. Thank You! Channel Support 👍 LIKE VIDEO 👊 SUBSCRIBE 🔔 PRESS BELL ICON ✍️ COMMENT Channel: / webstylepress Website: https://www.webstylepress.com FaceBook: https://www.facebook.com/webstylepress/ Twitter: https://twitter.com/webstylepress Instagram: https://www.instagram.com/webstylepress LinkedIn: https://www.linkedin.com/company/webs … GitHub: https://github.com/webstylepress #debugging #javascript #webdevelopment #TypeError #NotAFunction #javascripttutorial
Content
6.72 -> welcome to webstylepress if you
are new here consider subscribing
10.16 -> and hit bell icon have you encountered an
error like uncut type error some selector
16.88 -> is not a function or jQuery is not a function
or owl carousel is not a function or slick
24.08 -> slider is not a function and this error
may not be in every page of your website
30.88 -> it will be at some pages i will elaborate it by an
example i have got two pages here index and about
43.36 -> i have got jquery linked with it
and then custom.js in both pages
59.6 -> i will use owl carousel at one page from these
67.36 -> owl carousel is a popular
slider this is owl carousel v2.
76.24 -> here are the demos
80.16 -> this is basic demo for owl carousel
86.24 -> html is here and setup is here
initially this is the initializer
94.88 -> in index page i will link owl
carousel by using cdn js links
102.72 -> cdnjs.com and here i can search for owl carousel
111.76 -> this is owl carousel 2.
120.96 -> i will need its javascript file
owlcarousel.min.js copy script tag
127.76 -> and only index i will use it below jquery and
above custom.js in custom.js we will initialize it
138.96 -> and it depends on jquery it that is why
it is below jquery and before custom.js
149.6 -> then we will need owl carousel min dot
152.24 -> css
160.32 -> and let's copy default theme as
well all theme default here save
176.32 -> and now let's copy this example this
is html copy it and paste it here
189.2 -> and then we will need it set up this one
194.8 -> we are going to initialize it right this is
our class owl dash carousel this class at this
202.48 -> class we will initialize all carousel in our
custom.js file we will use document dot ready
217.84 -> function and here is our initializer
234.8 -> at owl carousel class
247.36 -> let's go to our index page and this
is index page and it is working
254.64 -> we have not implemented it at about page so we
right click here inspect and we go to console
274 -> then we go to about page
278.56 -> go to console and here you see
this error uncut type error
287.52 -> dollar sign dot owl carousel is not a
function the reason behind it is that
294.72 -> owl carousel is being initialized at an element
but that element is not present in about page
305.76 -> element is this one in index page but
this element is not present in about page
314.72 -> and we are trying to initialize it so
when jquery will not find this element
322.08 -> but we are initializing it at this class it will
complain the solution is to check if the element
332.56 -> exists only then we should initialize owl
carousel or any other library at it like this
345.84 -> if
354.64 -> jquery or dollar sign dot owl
carousel that is the class or element
363.92 -> dot length if this is present if this element
owl dash carousel is present then initialize
378.24 -> owl carousel for that element and now if
we refresh the about page the error is gone
390.88 -> and our slider still works at index page
398.72 -> you can also specify if owl dash carousel dot
length is not equal to zero that will also work
414.24 -> refresh and there is no error
421.44 -> so always check before you initialize
always check if element exists
429.28 -> this goes for any other library or plugin as
well whenever you initialize any functionality
436.16 -> for an element always check if that element is
present in page otherwise do not initialize it
444.64 -> that is the solution basically this if statement
make sure you use it make sure you check if the
454.24 -> element is present in page then initialize
script over it all right give this video
463.36 -> like subscribe to channel and press bell icon
stay tuned and i will see you in the next video
Source: https://www.youtube.com/watch?v=SdAt1qbWB-o