$ is not a function - jQuery error
It's really hard to tell, but one of the 9001 ads on the page may be clobbering the $
object.
jQuery provides the global jQuery
object (which is present on your page). You can do the following to "get" $
back:
jQuery(document).ready(function ($) {
// Your code here
});
If you think you're having jQuery problems, please use the debug (non-production) versions of the library.
Also, it's probably not best to be editing a live site like that ...
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>
There are quite lots of answer based on situation.
1) Try to replace '$' with "jQuery"
2) Check that code you are executed are always below the main jquery script.
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
});
</script>
3) Pass $ into the function and add "jQuery" as a main function like below.
<script type="text/javascript">
jQuery(document).ready(function($){
});
</script>
In my case I was using jquery on my typescript file:
import * as $ from "jquery";
But this line gives me back an Object $
and it does not allow to use as a function (I can not use $('my-selector')
). It solves my problem this lines, I hope it could help anyone else:
import * as JQuery from "jquery";
const $ = JQuery.default;