Home
> Twitter bootstrap > twiter bootstrap Navbar page selection (class=’active’)
twiter bootstrap Navbar page selection (class=’active’)
Hello All,
I have noticed a very common problem in twitter-bootstrap navbar , when user click on any item or navigate on other page by clicking any item from navbar, item not remain selected/active.
Here is the solution for above problem
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<meta charset=”utf-8″>
<title>AXSyst</title>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<meta name=”description” content=”Advanced Xpert Systems”>
<meta name=”author” content=””>
<!– Le styles –>
<link href=”css/bootstrap.css” rel=”stylesheet”>
<style type=”text/css”>
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href=”css/bootstrap-responsive.css” rel=”stylesheet”>
<!– Le HTML5 shim, for IE6-8 support of HTML5 elements –>
<!–[if lt IE 9]>
<script src=”http://html5shim.googlecode.com/svn/trunk/html5.js“></script>
<![endif]–>
<script src=”js/jquery.js”></script> <!–THIS NEEDS TO BE PLACED HERE BECAUSE $(document).ready(function(){ WON’T WORK. ALL OTHER JS ARE LOCATED IN _footer.php –>
</head>
<body>
<!–NavBar –>
<div>
<div>
<div>
<a data-toggle=”collapse” data-target=”.nav-collapse”>
<span></span>
<span></span>
<span></span>
</a>
<a href=”index.php”>MySite</a>
<div>
<ul id=ul_nav>
<li id=”li_home”><a href=”index.php”>Home</a></li>
<li id=”li_about”><a href=”about.php”>About</a></li>
<li id=”li_cont”><a href=”contact.php”>Contact</a></li>
</ul>
</div>
</div>
</div>
</div>
<!–NavBar end –>
Add following line of code to make selected node active in navbar….
———————————————————————————–
<script type=”text/javascript”>
function GetCurrentPageName() {
//method to get Current page name from url.
var PageURL = document.location.href;
var PageName = PageURL.substring(PageURL.lastIndexOf(‘/’) + 1);
return PageName.toLowerCase() ;
}
$(document).ready(function(){
var CurrPage = GetCurrentPageName();
switch(CurrPage){
case ‘index.php’:
$(‘#li_home’).addClass(‘active’) ;
break;
case ‘about.php’:
$(‘#li_about’).addClass(‘active’) ;
break;
case ‘contact.php’:
$(‘#li_cont’).addClass(‘active’) ;
break;
}
});
</script>
———————————————————————————–
Hope it helps !
Leave a Reply Cancel reply
Categories
- AngularJs (13)
- ASP.NET (104)
- C Programming (1)
- Code Project (2)
- CodeProject (1)
- Entity Framework (6)
- Ext.NEt (1)
- HTML5 (1)
- Interview .NET (2)
- Introduction (1)
- JQuery (1)
- Linq (1)
- Microsoft office (2)
- MOSS-(Sharepoint 2010) (2)
- MVC (5)
- Outlook (1)
- Sql Server (30)
- SSRS (5)
- TFS (1)
- Tips & Tricks (16)
- Twitter bootstrap (1)
- VB.NET (1)
- Visual Studio 2012/2013 (1)
- Web Services (1)
- Windows Workflow (1)
Top Posts & Pages
- Entity Framework : Could not load type System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider
- GridView: Findcontrol from HeaderTemplate/ItemTemplate
- Repeater control with multiple columns
- How to launch Bootstrap modal on page load
- USAePay Token error: 23 Specified source key not found
- MYSQL : How to skip first 10 records from a SELECT query and take next 10?
- EF code first - Model compatibility cannot be checked because the database does not contain model metadata
- How to Add space and increase width of Morris.Js Bar?
- MySQL : The user specified as a definer ('root'@'%') does not exist
- Define Composite Key in Model.(Core, EF Code First)
Recent Posts
- How to compile .NET Core Console Application as .exe File?
- Define Composite Key in Model.(Core, EF Code First)
- How to remove x from Internet Explorer ?
- The client and server cannot communicate, because they do not possess a common algorithm
- How to check if all items are the same in a list C#
- How to Collapse all #regions only(!) in C# (Visual Studio)
- Issue: Password field returned empty in edit mode
- Load XML from URL giving an error (The remote server returned an error: (401) Unauthorized.)
- How to use Variable in MySQL Like Clause ?
- Error :(System.Web.UI.HtmlControls.HtmlIframe) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl) in VS2017
Blog Stats
- 155,883 hits
Rahul Bhatia
Comments
aishwarya on remove pie chart slices labels… | |
Chakib on UpdatePanel and triggers from… | |
Mehdi Bennis on AngularJS With Asp.net Web API… | |
hnc24 on Send Email from a Static … | |
Rob on Send Email from a Static … |
Profile
Blog Stats
- 155,883 hits
Terrific. Thank you for sharing.
Thank you very much.
You gave me a solution !!!
You saved my day, thank you 🙂
thanks yar.. i have spent 2 hours then i had found your recipe. thanks alot
thanx for your help…
great!