Take a look at the live demonstration:
$(document).ready(function(){
$('nav a').click(function(){
$('nav a').removeClass('active');
$(this).addClass('active');
let link=$(this).attr('href');
window.location.href=link;
});
});
.nav >a.active>b{
color:blue;
}
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<div class="nav-scroller py-1 mb-2">
<nav class="nav d-flex justify-content-between">
<a class="active p-2 text-muted" href="https://fonts.google.com"><b> Business</b> </a>
<a class="p-2 text-muted" href="https://facebook.com"><b> Design </b></a>
<a class="p-2 text-muted" href="google.com"><b>Travel </b></a>
<a class="p-2 text-muted" href="#"><b> Opinion </b></a>
</nav>
</div>
</body>
</html>
Remember to pass section="yourpagename"
from the server side to the frontend side.
You can now display the active link in two ways:
1) The first method involves using a ternary condition and adding a class to the anchor tag:
Here's an example of how to do it:
<a class="p-2 text-muted <% section=="Business"?'active':'' %>" href="#"><b> Business</b> </a>
2) The second way is to add the active class using jQuery:
<a id="Business" class="p-2 text-muted" href="#"><b> Business</b> </a>
$(document).ready(function(){
var section= "Business" . <--send value from server side same as link id
$('#'+section).addClass('active');
});