Reputation: 1020
I got this jQuery code from here - Fiddle
$(document).ready(function () {
var $pagination = $('.qpagination');
var $lis = $pagination.find('li:not(#qprev, #qnext)');
$lis.filter(':gt(4)').hide();
$lis.filter(':lt(5)').addClass('active');
var $next = $('#qnext').click(function () {
var idx = $lis.index($lis.filter('.active:last')) || 0;
var $toHighlight = $lis.slice(idx + 1, idx + 6);
if ($toHighlight.length == 0) {
$prev.show();
return;
}
$next.show();
$lis.filter('.active').removeClass('active').hide();
$toHighlight.show().addClass('active')
});
var $prev = $('#qprev').click(function () {
var idx = $lis.index($lis.filter('.active:first')) || 0;
var start = idx < 4 ? 0 : idx - 4;
var $toHighlight = $lis.slice(start, start + 5);
if ($toHighlight.length == 0) {
$prev.hide();
return;
}
$next.show();
$lis.filter('.active').removeClass('active').hide();
$toHighlight.show().addClass('active')
});
}); // close jquery
However, when I copied the code and adjusted it according to my need it seems that it doesn't work. I get Uncaught SyntaxError: Unexpected token
error.
What seems to be the issue? & how can I fix it?
Edit: These are the errors I get from Chrome:
Undefined variable: pagination
Undefined variable: lis
Undefined variable: next
Undefined variable: toHighlight
Edit#2: I got the code to work after loading jQuery 2.2.1 on fiddle but it doesn't work on
https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js?ver=4.4.2
in Wordpress, this version is used. http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js?ver=4.4.2
it doesn't work on that one neither, How could I get it to work on ver=4.4.2?
Here is my live website: http://gulf-brokers.com/
Upvotes: 1
Views: 237
Reputation: 1020
Thanks for user3284463 got it working by removing the $ signs from JS variables as the browser confused JS variables with PHP variables and skipped them because I was echoing JS.
Upvotes: 0
Reputation: 9034
It looks like you are getting PHP errors which is adding certain characters to your script and giving you the expected expression, got '<'
at < br
. Looks like you need to fix your PHP errors first or switch off PHP error.
You could fix those errors Undefined variable: var
by simply defining a initial value for those variables. i.e. $pagination= "";
However, I would recommend turning off PHP errors since it should only be enabled at development stage and those errors do not seem to be that critical.
Upvotes: 1