Uffo
Uffo

Reputation: 10046

jQuery missing ; before statement

I have a problem with jQuery, my code looks ok, but I'm getting an error, which sounds like this:

missing ; before statement [Break on this error] }elseif($('.v_gallery li:first').hasClass('s')){\n

And my code looks like this:

_gallery_pag : function() {
$('#top_pag a').live('click',function() { var _type = $(this).attr('rel');

        switch(_type)
        {
            case '1':
                if($('.v_gallery li:last').hasClass('s'))
                {
                    $('.v_gallery li:first').find('a').click();
                }elseif($('.v_gallery li:first').hasClass('s')){
                    alert('You can\'t go back!You are at the first page!');
                }
            break;
        }
        return false;
    });     
}

I know, probably I miss spell checked something...because I don't see any problems.

10x guys

Upvotes: 0

Views: 3826

Answers (3)

Yuval Karmi
Yuval Karmi

Reputation: 26713

you wrote elseif instead of "else if" - in javascript, those are two different keywords.

here is your fixed code:

_gallery_pag : function() {
$('#top_pag a').live('click',function() { var _type = $(this).attr('rel');

                switch(_type)
                {
                        case '1':
                                if($('.v_gallery li:last').hasClass('s'))
                                {
                                        $('.v_gallery li:first').find('a').click();
                                }else if($('.v_gallery li:first').hasClass('s')){
                                        alert('You can\'t go back!You are at the first page!');
                                }
                        break;
                }
                return false;
        });             
}

Upvotes: 2

Tres
Tres

Reputation: 5674

"elseif" isn't a keyword in JavaScript, it should be "else if"

Upvotes: 1

Marius
Marius

Reputation: 58921

you misspelled else if. Add a space between else and if.

Upvotes: 1

Related Questions