Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Active Buttons with Bootstrap 3

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.

like image 861
megashigger Avatar asked Aug 22 '13 21:08

megashigger


People also ask

How do I make Bootstrap button active?

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> .

How can make button Unclickable in Bootstrap?

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.


1 Answers

Use JavaScript.

Example with jQuery:

$('ul li').click( function() {
    $(this).addClass('active').siblings().removeClass('active');
  });

DEMO

Or with more bootstrap:

Bootstrap 3 DEMO

like image 136
Eric Hotinger Avatar answered Oct 09 '22 18:10

Eric Hotinger