Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove data-toggle attribute when disabled

I have a list of tabs with elements that can be disabled - i.e. non-clickable. And when 'disabled' is added as a class, then the mouse over on the element is indicating that the tab is non-clickable. Unfortunately the element is clickable. I am trying to remove the datatoggle="tab" from the element when the element is disabled, but my jQuery skills aren't sufficient.

I have a ul of class="nav nav-tabs" with id="myTabs" And I'm trying to remove the data-toggle attribute with this jQuery statement:

$('#myTabs a').is('.disabled').removeAttr('data-toggle');

Bootply example

like image 750
peterbf Avatar asked Jul 07 '14 13:07

peterbf


People also ask

How do I turn off data toggle?

To disable a tab, we can remove the attribute : data-toggle=”tab” from the tab part enclosed under 'a' element.

What is data toggle attribute?

The data-toggle is an HTML-5 data attribute defined in Bootstrap. The advantage of using this is that, you can select a class or an id and hook up the element with a particular widget.

How do I make a tab not clickable?

How do I make a tab not clickable? You can use :not() CSS selector with pointer-events: none; to disable click event.


2 Answers

You can try this:-

$('#tabs li.disabled').find('a').removeAttr('data-toggle');

or

$('#tabs li.disabled a').removeAttr('data-toggle');

Demo

like image 108
Mohit Kumar Avatar answered Oct 03 '22 03:10

Mohit Kumar


$('#myTabs a').is('.disabled') returns a boolean: false - you cannot call removeAttr on this!

Second your disabled class is on your li, not your .

Try this:

$('#myTabs li.disabled a').removeAttr('data-toggle');
like image 39
rob Avatar answered Oct 03 '22 02:10

rob