I have the jQuery loaded fine, I've quadruple-checked, though I'm getting this error in FireBug "$ is not a function" and my code doesn't work.
Here's my code:
<script type="text/javascript"> $("ol li:nth-child(1)").addClass('olli1'); $("ol li:nth-child(2)").addClass("olli2"); $("ol li:nth-child(3)").addClass("olli3"); $("ol li:nth-child(4)").addClass("olli4"); $("ol li:nth-child(5)").addClass("olli5"); $("ol li:nth-child(6)").addClass("olli6"); $("ol li:nth-child(7)").addClass("olli7"); $("ol li:nth-child(8)").addClass("olli8"); $("ol li:nth-child(9)").addClass("olli9"); $("ol li:nth-child(10)").addClass("olli10"); $("ol li:nth-child(11)").addClass("olli11"); $("ol li:nth-child(12)").addClass("olli12"); $("ol li:nth-child(13)").addClass("olli13"); $("ol li:nth-child(14)").addClass("olli14"); $("ol li:nth-child(15)").addClass("olli15"); $("ol li:nth-child(16)").addClass("olli16"); $("ol li:nth-child(17)").addClass("olli17"); $("ol li:nth-child(18)").addClass("olli18"); $("ol li:nth-child(19)").addClass("olli19"); $("ol li:nth-child(20)").addClass("olli20"); </script>
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.
You may experience the “jQuery is not defined error” when jQuery is included but not loaded. Make sure that it's loaded by finding the script source and pasting the URL in a new browser or tab. The snippet of text you should look for to find the URL to test.
This is a standard JavaScript error when trying to call a function before it is defined. This error occurs if you try to execute a function that is not initialized or is not initialized correctly. This means that the expression did not return a function object.
In short, the "is not a function" error means that the value you're trying to invoke is not a function. The most common reasons this error occurs are: defining a variable with the same name that shadows the original object. calling a method on a value of a different type, e.g. calling the Array.
In Wordpress jQuery.noConflict()
is called on the jQuery file it includes (scroll to the bottom of the file it's including for jQuery to see this), which means $
doesn't work, but jQuery
does, so your code should look like this:
<script type="text/javascript"> jQuery(function($) { for(var i=0; i <= 20; i++) $("ol li:nth-child(" + i + ")").addClass('olli' + i); }); </script>
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