Switch between bootstrap tabs - html

I am a complete beginner at html and I'm trying to follow along with bootstrap but it appears there is something fundamental that I am overlooking. My code will make the tabs but I cannot get it to switch between the two tabs.
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Welcome to website</title>
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
Home
</li>
<li class="nav-item">
Data
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home">
<p>this is the home tab</p>
</div>
<div class="tab-pane fade" id="data">
<p>this is the data tab</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>

Seems to be just a naming issue.
Data
should be
Data
since the second tab's id is "data", not "profile".

Related

Bootstrap Pill Navigation not working on hosting

I am using a Bootstrap Pill Navigation (Bootstrap 4). Code is as below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="bootstrap-4.5.0-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="bootstrap-4.5.0-dist/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container-fluid">
<ul class="nav nav-pills">
<li class="nav-item"><a id="homeMenu" class="nav-link active" data-toggle="pill" href="#home">HOME</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="pill" href="#about">ABOUT</a></li>
<li class="nav-item"><a class="nav-link" data-toggle="pill" href="#contact">CONTACT</a></li>
</ul>
<div class="tab-content container-fluid">
<div id="home" class="tab-pane fade show active" style="background-color:yellow">
<h1>Home</h1>
</div>
<div id="about" class="tab-pane fade" style="background-color:red">
<h1>About</h1>
</div>
<div id="contact" class="tab-pane fade" style="background-color:orange">
<h1>Contact</h1>
</div>
</div>
</div>
</body>
</html>
This code works perfectly on localhost. But when it goes live, the links do not redirect to the respective id. Instead, the domain just shows as www.xyz.com/#(id) (when respective links are clicked) and stays on the initial view (which is the home tab). I am a newbie, so not really sure where I have gone wrong! Please help!
Try using a CDN version of jquery and bootstrap, i.e. replace these lines
<link href="bootstrap-4.5.0-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="bootstrap-4.5.0-dist/js/bootstrap.min.js"></script>
with
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
This is usually caused by Javascript, bootstrap and jquery files not being referenced properly from their respective folders since you are using them locally, make sure they are being targeted properly or use their direct CDN links to reference them.
Possible solutions are:
Add "../" to your script src links
This depends on the level or hierarchy of your folders.
Use the CDN versions of bootsrap files.
Put scripts at the bottom of your page instead of header area.
To create an anchor link you must name the target. You can use plain HTML.
Without href attribute, which indicates the hyperlink, the anchors are not seen as links, but their formatting is indistinguishable from "normal" text.
W3C explanation
So:
This is the link
<a name="home">This is the target</a>
In your case:
<!-- Links -->
<ul class="nav nav-pills">
<li>HOME</li>
<li>ABOUT</li>
<li>CONTACT</li>
</ul>
<!-- Sections -->
<div id="home">
<a name="home"><h1>Home</h1></a>
</div>
<div id="about">
<a name="about"><h1>About</h1></a>
</div>
<div id="contact">
<a name="contact"><h1>Contact</h1></a>
</div>
Try Bootstrap CDN from https://www.bootstrapcdn.com/ for {CSS, JS...} without any hesitation.
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Sometimes when we are working on the local machine, we just give a static path based on our OS, but when we deploy the website, the local development OS and Deployment OS differs from each other sometimes. So if we use CDN then the problem will solve with ease.
Easiest Solution is using a CDN (Manual approach also)
You can just plug the below snippet, and it should be working for you!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous">
</script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous">
</script>
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<div class="container-fluid py-2">
<ul class="nav nav-pills">
<li class="nav-item mr-2"><a id="homeMenu" class="nav-link active bg-primary text-white" data-toggle="pill" href="#home">HOME</a></li>
<li class="nav-item mr-2"><a class="nav-link bg-danger text-white" data-toggle="pill" href="#about">ABOUT</a></li>
<li class="nav-item mr-2"><a class="nav-link bg-warning text-white" data-toggle="pill" href="#contact">CONTACT</a></li>
</ul>
<div class="tab-content mt-2">
<div id="home" class="tab-pane fade show active bg-primary my-5 p-5">
<h1>Home</h1>
</div>
<div id="about" class="tab-pane fade bg-danger my-5 p-5">
<h1>About</h1>
</div>
<div id="contact" class="tab-pane fade bg-warning my-5 p-5">
<h1>Contact</h1>
</div>
</div>
</div>
</body>
</html>
You may try out this snippet directly from here JSFiddle Link
If you still wish to use relative paths:
Manual Approach (In Windows):
Create a folder called as libraries in the same directory as your index.html with the above code
Download the files using this link. Unzip it
Copy the bootstrap.min.css file from bootstrap-4.5.2-dist\css to the libraries directory
Copy the bootstrap.bundle.min.js from bootstrap-4.1.3-dist\js to the libraries directory
Download jquery files using this link. Copy the contents into a jquery-3.5.1.min.js file in the libraries directory
Update the HTML code as below:
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="./libraries/bootstrap.min.css">
<script src="./libraries/jquery-3.5.1.min.js"></script>
<script src="./libraries/bootstrap.bundle.min.js"></script></script>
</head>
PS: I know it is verbose, but just to be absolutely certain!

Switching an active bootstrap tab?

As far as I can see I've followed a w3 example exactly regarding bootstrap tabs (https://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp). However with my following code, the tabs don't change when clicked. The only tab displayed is the active tab. I'm not hugely familiar with bootstrap so I imagine the solution may probably be simple.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/login.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="js/login.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<!-- <div id="tabs" class="container"> -->
<ul class="nav nav-tabs">
<li class="active">
<a data-toggle="tab" href="#student">Student</a>
</li>
<li>
<a data-toggle="tab" href="#employee">Employee</a>
</li>
<li>
<a data-toggle="tab" href="#admin">Admin</a>
</li>
</ul>
<div class="tab-content">
<div id="student" class="tab-pane fade in active">
<h1>TEST</h1>
</div>
<div id="employee" class="tab-pane fade">
<h1>TEST2</h1>
</div>
<div id="admin" class="tab-pane fade">
<h1>TEST3</h1>
</div>
</div>
<!-- </div> -->
</div>
</body>
</html>
The example from W3 is not working either! Try this
<!DOCTYPE html>
<html lang="en">
<head>
<title>Login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/login.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="js/login.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation" class="active">Home</li>
<li role="presentation">Profile</li>
<li role="presentation">Messages</li>
<li role="presentation">Settings</li>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
TEST 1
</div>
<div role="tabpanel" class="tab-pane" id="profile">
TEST 2
</div>
<div role="tabpanel" class="tab-pane" id="messages">
TEST 3
</div>
<div role="tabpanel" class="tab-pane" id="settings">
TEST 4
</div>
</div>
</div>
</body>
</html>
And check: https://getbootstrap.com/docs/3.3/javascript/#tabs for more information
EDIT
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
This line must go before bootstrap.min.js, like this:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Bootstrap Tabs not working but code is looking fine

This is first time that my bootstrap tabs is not working my code is simple and everything looking OK but on my system it's not working.
Following is my code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Tabs </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" media="screen" title="no title">
</head>
<body>
<div class="container">
<ul class="nav nav-tabs" id="myTab">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">home</div>
<div class="tab-pane" id="profile">profile</div>
<div class="tab-pane" id="messages">messages</div>
<div class="tab-pane" id="settings">settings</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
Add data-toggle="tab" to anchor
<!DOCTYPE html>
<html lang="ENG">
<head>
<!-- Required meta tags always come first-->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title Page</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/css/bootstrap.css">
</head>
<body>
<div class="container">
<ul class="nav nav-tabs">
<li class="nav-item">
<a data-toggle="tab" href="#home" class="nav-link active">Active 1</a>
</li>
<li class="nav-item">
<a data-toggle="tab" href="#profile" class="nav-link">Active 2</a>
</li>
<li class="nav-item">
<a data-toggle="tab" href="#message" class="nav-link">Active 3</a>
</li>
<li class="nav-item">
<a data-toggle="tab" href="#settings" class="nav-link">Disabled</a>
</li>
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="home">home</div>
<div class="tab-pane fade" id="profile">profile</div>
<div class="tab-pane fade" id="message">messages</div>
<div class="tab-pane fade" id="settings">settings</div>
</div>
</div>
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<!-- Bootstrap JavaScript -->
<script src="https://www.atlasestateagents.co.uk/javascript/tether.min.js"></script><!-- Tether for Bootstrap -->
<script src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script>
</body>
</html>

Something Weird in my markup. Twitter bootsrap tab not working

I designed a markup and i'm trying to make a tab on bootsrap with jquery. I wrote markup code as below. Please examine why the tabs are not working? What wrong with my code.
in javascript console it showing
ReferenceError: $ is not defined
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Just Live 24</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/tv-theme.css">
<link href="css/main_pricetable.css" rel="stylesheet">
</head>
<body>
<div class="col-md-6">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist" id="myTab">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">bmnmn,b,mbn...</div>
<div class="tab-pane" id="profile">.werewr..</div>
<div class="tab-pane" id="messages">.jkhk..</div>
<div class="tab-pane" id="settings">llkjlk...</div>
</div>
<script>
$('#myTab a').click(function (e) {
e.preventDefault();
$(this).tab('show');
})</script>
</div>
<hr>
</body>
</html>
Most probably you forgot to attach http in script src attribute.
src="http://code.jquery.com/jquery-1.11.0.min.js"
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"
As a result browser is unable to fetch scripts and is not recogizing jquery shorthand (i.e. $).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example of Twitter Bootstrap 3 Tabs</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
</head>
<body>
<div class="col-md-6">
<ul class="nav nav-tabs">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
</ul>
</div>
<div class="tab-content" style="margin-left:20px;">
<div class="tab-pane active" id="home">bmnmn,b,mbn...</div>
<div class="tab-pane" id="profile">.werewr..</div>
<div class="tab-pane" id="messages">.jkhk..</div>
<div class="tab-pane" id="settings">llkjlk...</div>
</div>
</div>
<hr>
</body>
</html>
http://jsfiddle.net/7r6kgooh/

HTML, CSS Bootstrap

I need to make menu in bootstrap with nav-pills. I have 5 sections in menu and each section have text (Like first is "aaaa", second is "bbbb", etc). If I click on first section it shows text "aaaa" and click on second section it shows text "bbbb", but if I click on third/fourth/ fifth section nothing happens.
Any ideas how to resolve this? Thanks in advance.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>APK Market</title>
<link rel="stylesheet" type="text/css" href="style/style.css">
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="header">
<div class="logo"></div>
<div class="navbar">
<ul class="nav nav-pills">
<li class="active"><a data-toggle="tab" href="#games">Games</a></li>
<li><a data-toggle="tab" href="#apps">Apps</a></li>
<li><a data-toogle="tab" href="#live_wallpapers">Live Wallpapers</a></li>
<li><a data-toogle="tab" href="#themes">Themes</a></li>
<li><a data-toogle="tab" href="#archive">Archive</a></li>
</ul>
</div>
</div>
<div class="tab-content">
<div id="games" class="tab-pane active">aaaaaaaaaaaa</div>
<div id="apps" class="tab-pane">bbbbbbbbbbbbb</div>
<div id="live_wallpapers" class="tab-pane">ccccccccccc</div>
<div id="themes" class="tab-pane">ddddddddddd</div>
<div id="archive" class="tab-pane">eeeeeeeeee</div>
</div>
</div>
<div class="content"></div>
<div class="sidebar"></div>
<div class="footer"></div>
<script src="https://code.jquery.com/jquery.js"></script>
<script src="bootstrap/js/bootstrap.js"></script>
</body>
</html>
You spelled "toggle" wrong.
<li><a data-toogle="tab" href="#live_wallpapers">Live Wallpapers</a></li>
<li><a data-toogle="tab" href="#themes">Themes</a></li>
<li><a data-toogle="tab" href="#archive">Archive</a></li>
change data-toogle to data-toggle..