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:
There are two possible reasons for that error:
try to put your jquery code in document.ready, like this:
$(document).ready(function(){
....your code....
});
cheers
When jQuery is not present you get $ is undefined
and not your message.
Did you check if you don't have a variable called $ somewhere before your code?
Inspect the value of $ in firebug to see what it is.
Slightly out of the question, but I can't resist to write a shorter code to your class assignment:
var i = 1;
$("ol li").each(function(){
$(this).addClass('olli' + i++);
});
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>
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 ...