In my navbar, I want my buttons to become active (shaded) when I click on them. Right now, I can only permanently make them active or non-active but don't know how to have it change once I click on them. I'm using the new Bootstrap (3.0).
For example:
Non-Active
<li><%= link_to "Contact", contact_path %></li>
Active
<li class="active"><%= link_to "About", about_path %></li>
I want it to be active/non-active depending on whether the current page is selected or not.
Add data-toggle="button" to toggle a button's active state. If you're pre-toggling a button, you must manually add the .active class and aria-pressed="true" to the <button> .
Active/Disabled Buttons The class . active makes a button appear pressed, and the disabled attribute makes a button unclickable. Note that <a> elements do not support the disabled attribute and must therefore use the . disabled class to make it visually appear disabled.
Use JavaScript.
Example with jQuery:
$('ul li').click( function() {
$(this).addClass('active').siblings().removeClass('active');
});
DEMO
Or with more bootstrap:
Bootstrap 3 DEMO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With