最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Why is jsfiddle giving me the error "SyntaxError: Unexpected token :"? - Stack Overflow

matteradmin4PV0评论

I'm using structured javascript code and it works fine on my puter. But when I add it to jsFiddle, it gives me the followinge error:

SyntaxError: Unexpected token :

My code looks like this:

var StentGallery = {
    gallery: null,

    init : function(){
            this.gallery = jQuery('#gallery-list-ui');
            this.resizeImage();
        }
    }
    (...)
}

Does anyone know why this is not working in jsFiddle?
See my fiddle here: /

I'm using structured javascript code and it works fine on my puter. But when I add it to jsFiddle, it gives me the followinge error:

SyntaxError: Unexpected token :

My code looks like this:

var StentGallery = {
    gallery: null,

    init : function(){
            this.gallery = jQuery('#gallery-list-ui');
            this.resizeImage();
        }
    }
    (...)
}

Does anyone know why this is not working in jsFiddle?
See my fiddle here: https://jsfiddle/smyhbckx/

Share Improve this question asked Dec 6, 2015 at 18:20 StevenSteven 19.5k49 gold badges156 silver badges263 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 5

There's a syntax error in your code:

var StentGallery = {
    gallery: null,

    init : function(){
           this.gallery = jQuery('#gallery-list-ui');
           this.resizeImage();
           } // <----- this is prematurely closing your object
    }, 

    resizeImage: function(){
    ...

To fix this, simply remove that bracket:

var StentGallery = {
    gallery: null,

    init : function(){
           this.gallery = jQuery('#gallery-list-ui');
           this.resizeImage();
    },

    resizeImage: function(){
    ...

There's an extra closing '}' for your init function.

Post a comment

comment list (0)

  1. No comments so far