5

My goal is to overload Bootstrap nav pall click event, and I was happy to come across this post

I've modified the code the following way to make it work for pills, but I'm helpless to understand why it doesn't work.

HTML:

<ul class="nav nav-pills" id="orders_tab">
                <li class="active"><a data-toggle="pill" href="#orders_for_today">Текущие</a></li>
                <li><a data-toggle="pill" href="#orders_sent_to_vendors">Ожидающие</a></li>
                <li><a data-toggle="pill" href="#inventories">Остатки</a></li>
                <li><a data-toggle="pill" href="#sales">Продажи</a></li>
                <li><a data-toggle="pill" href="#sales_aggregate">Аггрегированные продажи</a></li>
                <li role="presentation" class="dropdown">
                    <a class="dropdown-toggle" data-toggle = "dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
                      Прочее <span class="caret"></span>
                    </a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Action</a></li> 
                        <li><a href="#orders_products">Продукты</a></li>
                    </ul>
                </li>
            </ul> 

JS

$('a[data-toggle="pill"]').on('shown.bs.pill', function (e) {
        var target = $(e.target).attr("href") // activated tab
        alert(target);
    });
Community
  • 1
  • 1
Edgar Navasardyan
  • 4,261
  • 8
  • 58
  • 121

2 Answers2

5

Bootstrap pills and tabs use same javascript. Just the .nav-pills instead of .nav-tabs is different.

Replace the data-toggle="pill" with data-toggle="tab" everywhere and should work.

kodikotriftis
  • 156
  • 1
  • 3
5

In Bootstrap nav-pills aka is a styling component not an js component. So data-toggle will be data-toggle="tab".

Update Fiddle for your code Fiddle

data-toggle="tab"

only change required.

-Help :)

Help
  • 650
  • 3
  • 8