SSI and class="active"
How do I add class="active" to pages on a site using SSI?
How do I add class="active" to pages on a site using SSI?
https://forums.adobe.com/people/Nancy+OShea wrote
This is super easy to do with jQuery.
Assign "active" class to navbar item based on current page URL with jQuery · GitHub
Are you sure the code at that link still works, its 4 years old?
I've tried it every which way and can't get it to work.
I found another jquery solution that does work in a similar fashion but is flawed in the workflow, so Im just trying to test the one at the link you provided to see if it functions any differently.
Anyway it seems they may probably work the same finding the file 'path' name which means you have to keep updating the path between local development and remote development:
<li><a href="http://localhost/editor_test/page_marker/home.php">Home</a></li>
<li><a href="http://www.yourDomainName.co.uk/editor_test/page_marker/home.php">Home</a></li>
I dont know if jQuery can just find the file name and compare that rather than the path, which would make the workflow more streamlined.
EDITED.
Apparently you can pull the file name
var current = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
So you'd really be wanting to compare the file name and NOT the pathname.
Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Page Marker</title>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(function(){
var current = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
$('.nav li a').each(function(){
var $this = $(this);
// if the current path is like this link, make it active
if($this.attr('href').indexOf(current) !== -1){
$this.addClass('active');
}
})
})
</script>
<style>
.active {
background-color: yellow;
}
</style>
</head>
<body>
<ul class="nav">
<li><a href="home.php">Home</a></li>
<li><a href="about.php">About</a></li>
</ul>
</body>
</html>
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.