Bootstrap tab click preventDefault doesn't work


Stacey

I'm using bootstrap 3.3 and following the tabs in the documentation.

The simplest code given in the documentation doesn't work for me and I can't figure out why.

$('#mainTabs a').click(function (e) {
            e.preventDefault()
            console.log('Clicked');
        });

when i use

show.bs.tab

event, preventDefault is valid. But for some reason the click won't. The console is printing "clicked" but it doesn't prevent the tab from changing.

Basically, I'm trying to intercept tab changes, show the modal and show or not show new tabs based on user input.

please help.

Hardik Shah

If it e.preventDefault();doesn't work, you have to use it e.stopImmediatePropagation();instead.

For more information, check out: What is the difference between event.stopPropagation and event.preventDefault?

$("#mainTabs a").click(function(e) {
     e.stopImmediatePropagation();
});

If you have attached other event handlers to the link, you should investigate e.stopPropagation()and e.stopImmediatePropagation(). Note that return false is equivalent to calling event.preventDefault()sum event.stopPropagation().

EDIT==========

use return false;.

Related


Bootstrap tab click preventDefault doesn't work

Stacey I'm using bootstrap 3.3 and following the tabs in the documentation. The simplest code given in the documentation doesn't work for me and I can't figure out why. $('#mainTabs a').click(function (e) { e.preventDefault() console.lo

Bootstrap tab click preventDefault doesn't work

Stacey I'm using bootstrap 3.3 and following the tabs in the documentation. The simplest code given in the documentation doesn't work for me and I can't figure out why. $('#mainTabs a').click(function (e) { e.preventDefault() console.lo

Bootstrap tab click preventDefault doesn't work

Stacey I'm using bootstrap 3.3 and following the tabs in the documentation. The simplest code given in the documentation doesn't work for me and I can't figure out why. $('#mainTabs a').click(function (e) { e.preventDefault() console.lo

Bootstrap tab click preventDefault doesn't work

Stacey I'm using bootstrap 3.3 and following the tabs in the documentation. The simplest code given in the documentation doesn't work for me and I can't figure out why. $('#mainTabs a').click(function (e) { e.preventDefault() console.lo

event.preventDefault() doesn't work on click

Dai Du I want to stop event click. I tried using event.preventDefault()"ul li a" to stop the event. <ul> <li><a href="#">Click here</a></li> </ul> <script type="text/javascript"> $(document).ready(function() { $(document).on('click','ul li a', functi

event.preventDefault() doesn't work on click

Dai Du I want to stop event click. I tried using event.preventDefault()"ul li a" to stop the event. <ul> <li><a href="#">Click here</a></li> </ul> <script type="text/javascript"> $(document).ready(function() { $(document).on('click','ul li a', functi

Show Bootstrap tab loaded with Ajax on first click doesn't work

dirty encoder I am trying to load the content of a given tab using Ajax. I'm rendering the first tab active on the server, and the other tabs are active and loaded using Ajax. The problem I've isolated (without Ajax) is here . HTML: <h1>Hello, tabs!</h1> <div

Show Bootstrap tab loaded with Ajax doesn't work on first click

dirty encoder I am trying to load the content of a given tab using Ajax. I'm rendering the first tab active on the server, and the other tabs are active and loaded using Ajax. The problem I've isolated (without Ajax) is here . HTML: <h1>Hello, tabs!</h1> <div

Tab click doesn't work

rookie I tried following this demo https://www.youtube.com/watch?v=PP3x4crHBog but since I already named other tags I can't name the same thing, so I made some changes to the variable names and Using the skins and all the formatting, but whenever I click the l

Tab click doesn't work

rookie I tried to follow this demo https://www.youtube.com/watch?v=PP3x4crHBog but couldn't name the same since I already named other tags, so I made some changes to the variable names and Using the skins and all the formatting, but whenever I click the login

jQuery UI tab beforeLoad preventDefault doesn't work

Judge God Somehow the e.preventDefault()on beforeLoad()event in jQuery UI Tabs is not working properly. Here is a small example: <div id="tabs"> <ul> <li><a href="#exampleExistingTab">Existing Tab</a></li> <li><a href="/path/to/remote/tab">

jQuery UI tab beforeLoad preventDefault doesn't work

Judge God The e.preventDefault()on beforeLoad()event in jQuery UI Tabs is not working properly. Here is a small example: <div id="tabs"> <ul> <li><a href="#exampleExistingTab">Existing Tab</a></li> <li><a href="/path/to/remote/tab">Remote T

jQuery UI tab beforeLoad preventDefault doesn't work

Judge God Somehow the e.preventDefault()on beforeLoad()event in jQuery UI Tabs is not working properly. Here is a small example: <div id="tabs"> <ul> <li><a href="#exampleExistingTab">Existing Tab</a></li> <li><a href="/path/to/remote/tab">

Navigation tab doesn't change with click in bootstrap

Man · ((Peyman Omidi) I've created two tabs for "Fixtures" and "Results", but when I click on the "Results" tab, nothing changes and it remains in the "Fixtures" tab! Here is my code: <section> <div class="container"> <div class="row"> <div

Navigation tab doesn't change with click in bootstrap

Man · ((Peyman Omidi) I've created two tabs for "Fixtures" and "Results", but when I click on the "Results" tab, nothing changes and it remains in the "Fixtures" tab! Here is my code: <section> <div class="container"> <div class="row"> <div

jQuery .click() event.preventDefault() doesn't work

Richard King: I'm building an extensible web application by putting scripts into a preset directory. The script needs to read the file header before going to the page, so I need to use .preventDefault() when I click the link and run some JScript first. Unfortu

jQuery .click() event.preventDefault() doesn't work

Richard King: I'm building an extensible web application by putting scripts into a preset directory. The script needs to read the file header before going to the page, so I need to use .preventDefault() when I click the link and run some JScript first. Unfortu

jQuery .click() event.preventDefault() doesn't work

Richard King I'm building an extensible web application by putting scripts into a preset directory. The script needs to read the file header before going to the page, so I need to use .preventDefault() when I click the link and run some JScript first. Unfortun

Deleting event.preventDefault on click doesn't work

Yus I have this code that prevents the default behavior for all elements: $('body *').click(function(e){ e.stopPropagation(); e.preventDefault(); }); Now, I want to programmatically click a link in the page, but first I have to remove the e.preventDefault();

jQuery .click() event.preventDefault() doesn't work

Richard King: I'm building an extensible web application by putting scripts into a preset directory. The script needs to read the file header before going to the page, so I need to use .preventDefault() when I click the link and run some JScript first. Unfortu

Deleting event.preventDefault on click doesn't work

Yus I have this code that prevents the default behavior for all elements: $('body *').click(function(e){ e.stopPropagation(); e.preventDefault(); }); Now, I want to programmatically click a link in the page, but first I have to remove the e.preventDefault();

Ionic tab click doesn't work

gfels Sometimes I don't understand why the Ionic is so stiff. I have an input and a label stacked on top of each other: <ion-item> <ion-label stacked (click)="labelClick($event)" [innerHTML]="htmlString"></ion-label> <ion-input ></ion-input> And the labelCli

Click event doesn't work on tab

ask I have the following jsx code that doesn't work with mouseclicks: import React from 'react'; import Tabs from 'material-ui/lib/tabs/tabs'; import Tab from 'material-ui/lib/tabs/tab'; const Main = () => ( <div> <Tabs> <Tab label="Item One" >

Ionic tab click doesn't work

gfels Sometimes I don't understand why the Ionic is so stiff. I have an input and a label stacked on top of each other: <ion-item> <ion-label stacked (click)="labelClick($event)" [innerHTML]="htmlString"></ion-label> <ion-input ></ion-input> And the labelCli

Ionic tab click doesn't work

gfels Sometimes I don't understand why the Ionic is so stiff. I have an input and a label stacked on top of each other: <ion-item> <ion-label stacked (click)="labelClick($event)" [innerHTML]="htmlString"></ion-label> <ion-input ></ion-input> And the labelCli

Ionic tab click doesn't work

gfels Sometimes I don't understand why the Ionic is so stiff. I have an input and a label stacked on top of each other: <ion-item> <ion-label stacked (click)="labelClick($event)" [innerHTML]="htmlString"></ion-label> <ion-input ></ion-input> And the labelCli