Radu Dragomir
Radu Dragomir

Reputation: 660

jQuery is undefined & unexpected token

I have this script that positions a div's background in proportion with the window size:

// JavaScript Document
var jQNC = jQuery.noConflict();

jQNC(document).ready( function () {
    setPunchMargin()
    jQNC(window).resize( function () {
        setPunchMargin();
    });
});

function setPunchMargin() {
    var windowWidth = jQNC(window).width();
    if (windowWidth <= 980) {
        var margin = 0;
    } else {
        var margin = Math.round((windowWidth - 980) / 2);
    }
    jQNC('.punch').css('background-position', margin + 'px 320px');
}

It works like a charm on my local machine, but when uploading it to the server i get jQuery is undefined and on the jquery library i get unexpected token error.

Can you tell me what is wrong here?

Thank you, Radu.

Upvotes: 0

Views: 1301

Answers (2)

Christopher Thrower
Christopher Thrower

Reputation: 730

You have jQuery included two times;

<script language="javascript" src="http://punchid.com/test/wp-content/themes/punch/js/jquery-1.6.1-min.js" type="text/javascript"></script>

And here;

<script type='text/javascript' src='http://punchid.com/test/wp-includes/js/jquery/jquery.js?ver=1.4.4'></script>

The latter is an older version, I'd suggest removing that one from the code - But double check everything still works correctly afterwards.

Upvotes: 2

Francis Gilbert
Francis Gilbert

Reputation: 3442

This looks like you are not uploading or referencing jQuery correctly. Try using an absolute reference to a Jquery CDN like: http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js

(where 1.5.1 is the version of Jquery you'd need).

Upvotes: 1

Related Questions