Hi I Know this has been asked before but no answer on here seems to help me.
I have this block of JS:
$(document).ready(function() {
$('.play-icon-hover').hover(function() {
$('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
$('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
And I seem to be getting this error but I have no idea why?
Uncaught TypeError: $(...).ready is not a function
Thanks
The TypeError: "x" is not a function can be fixed using the following suggestions: Paying attention to detail in code and minimizing typos. Importing the correct and relevant script libraries used in code. Making sure the called property of an object is actually a function.
ready is not a function" error occurs for multiple reasons: Placing second set of parenthesis after the call to the ready() method. Loading the jQuery library after running your JavaScript code. Forgetting to load the jQuery library.
$( document ). ready()A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ). ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute.
ready() and $(window). load() event is that the code included inside onload function will run once the entire page(images, iframes, stylesheets,etc) are loaded whereas the $(document). ready() event fires before all images,iframes etc. are loaded, but after the whole DOM itself is ready.
You are using Prototype.js as well as jQuery.js. If you wanna use jQuery, it is better to encapsulate your code inside an IIFE like this:
(function ($) {
// jQuery code using $
})(jQuery);
So the solution for your issue is either you change $ to jQuery:
jQuery(document).ready(function() {
jQuery('.play-icon-hover').hover(function() {
jQuery('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
jQuery('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
Or, use a IIFE:
(function ($) {
$(document).ready(function() {
$('.play-icon-hover').hover(function() {
$('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
$('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
})(jQuery);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With