I am getting this error: “TypeError: $ is not a function $(‘#slider’).list({“
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="http://plumbsimple.com/wp-content/themes/bootstrapwp-87/js/basic-jquery-slider.min.js"></script>
<script type="text/javascript">
window.$ = jQuery;
$(document).ready(function() {
$('#slider').list({
'animation' : 'slide',
'width' : 700,
'height' : 300
});
});
</script>
Data in header:
<div id="slider"><ul class="list">
<li><img src="<?php bloginfo( 'template_url' );?>/img/beach.jpg"></li>
<li><img src="<?php bloginfo( 'template_url' );?>/img/hp-computers.jpg"></li>
</ul>
</div>
There are 2 variants:
$
function because ofprototype.js
or something, then try to usejQuery
function instead of$
.WP by default puts jQuery in
noConflict
mode: (source)Which can be easily tested on the console:
So, if you don’t use any other library that could conflict with jQuery’s
$
, you can re-alias jQuery to$
:Put that line at the very beginning of your first script after the jQuery library and it will work fine.
Also, you can just replace all
$
references withjQuery
or use use a different alias in case you’d have a conflict with prototype or another library.edit: There’s something in fact overwriting your global
$
as well. You can wrap your code in an IIFE to create a scope where you can safely use the$
alias:More than likely writing the replace first “$” with “jQuery” and passing the “$” to the function will make that error go away. Example below.
If you looke at the wordpress codex, they provide the solution of what is going on.
http://codex.wordpress.org/Function_Reference/wp_enqueue_script