I want to add class to link if it's the current URL.
The URL structure is like that: http://localhost/search?date=2010&number_of_books=10
;
/search?query1&query2&query3...
I can add class to a 'current URL link' with that code:
<script>
$(document).ready(function($) {
$("a").each(function () {
var href = $(this).attr('href');
var current_url = location.pathname + location.search;
if (current_url == href) {
$(this).addClass('active');
}
});
});
</script>
How can I check if the current page URL (search parameters) and a link's URL (search parameters) same then I can add a class to this link?
For example if I'm on the page: /search?date=2010&author=Adam+Smith
and if a link href is /search?author=Adam+Smith&date=2010
then I want to add class to this link, too. (Note: Consider that, both two link has the same parameters.)