Mustapha Aoussar
Mustapha Aoussar

Reputation: 5923

Uncaught Error: Syntax error, unrecognized expression:

I am trying to use jquery.cookie to handle the vertical accordion menu cookie.

var active = $.cookie('active'),
    $nav = $("#nav > li > a"),
    $active = $nav.filter('.' + active);

$nav.click(function(e, speed) {
    $("#nav li ul").slideUp(speed);
    if (!$(this).next().is(":visible")) {
        $(this).next().slideDown(speed);
        $.cookie('active', this);
    }
});
if ($active.next().is(':hidden')) {
    $active.trigger('click', [0]);
}

Fiddle Demo

When I click on dropdown menu I get this error on Firebug:

Uncaught Error: Syntax error, unrecognized expression: . 

I do not know what I did wrong. Thanks for any help!

Upvotes: 0

Views: 1045

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074266

I suspect the problem is here:

$active = $nav.filter('.' + active);

If active is "" (or anything that coerces to ""), that becomes $nav.filter("."), which is an invalid CSS expression. I get that exact error if I feed an invalid expression into filter.

Upvotes: 2

Related Questions