Reputation: 41
I am using the following script to highlight the current page on a tumblr blog, which I got from here: http://www.eznetu.com/current-link.html
$(function(){
$('a').each(function() {
if ($(this).prop('href') == window.location.href) {
$(this).addClass('current');
}
});
});
This works great, but there is one problem: the link must be identical to the current URL or it will not work. In other words, if the link points to blog.tumblr.com/tagged/red, it works fine, but if the user naviagtes to the next page, i.e. blog.tumblr.com/tagged/red/page/2, it will not work.
I am absolutely clueless about javascript, and was wondering if there is a way to insert a wildcard so that it picks up cases like the one outlined above. I would greatly appreciate any insight on this.
Upvotes: 1
Views: 60
Reputation: 34011
You can simplify it a bit by using the CSS attribute selector:
$('a[href*=' + window.location.href + ']').addClass('current');
Upvotes: 1