forrest
forrest

Reputation: 11012

jQuery - Syntax Error

I am using the following to identify the current selected (active) link in a site:

 $(function(){
 var path = location.pathname.substring(1);
 if ( path )
 $('#sidebar_content a[@href$="' + path + '"]').attr('class', 'selected');
 });

It appears to identify the path properly but also generates an error

Error: uncaught exception: Syntax error, unrecognized expression: [@href$="clinics/ohs_north_carolina"]

The page source does not show that the link has the class added.

Would appreciate some help.

Thanks.

Upvotes: 2

Views: 2406

Answers (1)

Ayman Hourieh
Ayman Hourieh

Reputation: 137416

[@attr] style selectors were removed in jQuery 1.3. Remove the @ symbol and it should work.

$('#sidebar_content a[href$="' + path + '"]').attr('class', 'selected');

From the docs:

Note: In jQuery 1.3 [@attr] style selectors were removed (they were previously deprecated in jQuery 1.2). Simply remove the '@' symbol from your selectors in order to make them work again.

Upvotes: 6

Related Questions