Pete
Pete

Reputation: 532

Get the window location has and apply class to a matching div

As the title says, I'm getting the location hash and storing it in a var. I'm then searching for a link with a name attribute which matches the hash and adding a class to it.

The code I'm currently using is:

var hash = window.location.hash.substring(1);
$('a[name*='+hash+']').addClass("boo");

Not having any luck though? Any suggestions would be greatly appreciated.

Upvotes: 0

Views: 44

Answers (1)

Amin Jafari
Amin Jafari

Reputation: 7207

your code is fine, just drop the star (*) and add quotations to hash:

var hash = window.location.hash.substring(1);
$('a[name="'+hash+'"]').addClass("boo");

Upvotes: 1

Related Questions