Jon Harding
Jon Harding

Reputation: 4946

jquery .contains() syntax odd error

I have an odd error happening in jquery.

When I got to: http://www.autopartscenter.net/

I get a .js error when trying to do a search

However, if I go to http://www.autopartscenter.net/home (which is the exact same page) the search works fine.

I've narrowed down the culprit jquery causing it to break: http://www.autopartscenter.net/assets/js/common.js

$('#ddlMake option:contains(' + make[1] + ')').attr('selected', true);

It seems to be some sort of syntax error.

Any help would be great!

Upvotes: 2

Views: 358

Answers (1)

Leon
Leon

Reputation: 988

I think it's because of this

var make = location.pathname.split("/");

when you are in this page http://www.autopartscenter.net/home, make[1] is equal to 'home' while in this page http://www.autopartscenter.net make[1] is undefined that's why the following code breaks

$("#ddlMake option:contains(" + make[1] + ")").attr('selected', true);

Upvotes: 4

Related Questions