× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

how to set active class to nav menu from twitter bootstrap

Leniel Macaferi
Feb 02, 2015
<p>You can use this <code>JavaScript\jQuery</code> code:</p> <pre><code>// Sets active link in Bootstrap menu // Add this code in a central place used\shared by all pages // like your _Layout.cshtml in ASP.NET MVC for example $('a[href="' + this.location.pathname + '"]').parents('li,ul').addClass('active'); </code></pre> <p>It'll set the <code>&lt;a&gt;</code>'s parent <code>&lt;li&gt;</code> and the <code>&lt;li&gt;</code>'s parent <code>&lt;ul&gt;</code> as active.</p> <p>A simple solution that works!</p> <hr> <p>Original source:</p> <p><a href="http://totalprogus.blogspot.com.br/2013/12/bootstrap-add-active-class-to-li.html" rel="nofollow">Bootstrap add active class to li</a></p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/15082316/how%20to%20set%20active%20class%20to%20nav%20menu%20from%20twitter%20bootstrap/25705971">Stack Overflow</a>.</p>
comments powered by Disqus