Bootstrap 5 List group dispose() Method
Last Updated :
15 Mar, 2025
Bootstrap's List group dispose() Method is utilized to dispose of a tab of the list group. This method can work only after the instance is pre-initialized.
The dispose() method is used to dispose of the list group's tab i.e. destroy the instance of the particular list group tab from the DOM.
Syntax:
var a = document.getElementById("list_group-tab-id");
a.dispose();
Parameters: This method accepts arguments from either an HTML element or its selector.
Example 1: This example demonstrates the usage of the dispose() method on a list group and disposal of an individual tab and also getting the instance of the tab to dispose of the tab in the list group. You can see the list group instance before and after disposing of the list group tab.
HTML
<html>
<head>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
</head>
<body class="m-2">
<h1 class="text-success">GeeksforGeeks</h1>
<h3>Bootstrap 5 List dispose() Method</h3>
<div role="tabpanel">
<div class="list-group" id="myList"
role="tablist">
<a class="list-group-item
list-group-item-action active"
data-bs-toggle="list"
href="#ds" role="tab">
Data Structures
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#algo" role="tab">
Algorithms
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#bs" role="tab">
Bootstrap
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#cpp" role="tab">
C++
</a>
</div>
<div class="tab-content mt-3 p-3 bg-light">
<div class="tab-pane active"
id="ds" role="tabpanel">
A data structure is a group of data elements
that provides the easiest way to store and
perform different actions on the data of
the computer. A data structure is a
particular way of organizing data in a
computer so that it can be used
effectively.
</div>
<div class="tab-pane" id="algo" role="tabpanel">
The word Algorithm means ” A set of finite
rules or instructions to be followed in
calculations or other problem-solving
operations ” Or ” A procedure for solving
a mathematical problem in a finite number
of steps that frequently involves
recursive operations”
</div>
<div class="tab-pane" id="bs" role="tabpanel">
Bootstrap is a free and open-source
collection of CSS and JavaScript/jQuery
code used for creating dynamic websites
layout and web applications.
</div>
<div class="tab-pane" id="cpp" role="tabpanel">
C++ is a general-purpose programming
language and is widely used nowadays for
competitive programming. It has imperative,
object-oriented and generic programming
features.
</div>
</div>
</div>
<br>
<button class="btn btn-danger" id="disposeDSBtn">
Dispose DS Tab
</button>
<button class="btn btn-danger" id="disposeBSBtn">
Get instance and Dispose BS Tab
</button>
<script>
const dsEl = document.getElementById('ds');
const dsElTab = new bootstrap.Tab(dsEl)
const bsEl = document.getElementById('bs');
const bsElTab = new bootstrap.Tab(bsEl)
const disDSBtn =
document.getElementById('disposeDSBtn')
const disBSBtn =
document.getElementById('disposeBSBtn')
disDSBtn.addEventListener('click', function () {
// Instance before disposing
console.log(dsElTab);
dsElTab.dispose()
// Instance after disposing
console.log(dsElTab);
})
disBSBtn.addEventListener('click', function () {
var bsInstance =
bootstrap.Tab.getInstance(bsEl);
// Instance before disposing
console.log(bsInstance);
bsInstance.dispose()
// Instance after disposing
console.log(bsInstance);
})
</script>
</body>
</html>
Output:
Example 2: This example demonstrates the usage of the dispose() method on a list group and dispose an individual tab and also creating and getting the instance of the tab to dispose the tab of the list group.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<script src=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js">
</script>
</head>
<body class="m-2">
<h1 class="text-success">
GeeksforGeeks
</h1>
<h3>
Bootstrap 5 List dispose() Method
</h3>
<div role="tabpanel">
<div class="list-group"
id="myList" role="tablist">
<a class="list-group-item
list-group-item-action active"
data-bs-toggle="list"
href="#ds" role="tab">
Data Structures
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#algo" role="tab">
Algorithms
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#bs" role="tab">
Bootstrap
</a>
<a class="list-group-item
list-group-item-action"
data-bs-toggle="list"
href="#cpp" role="tab">
C++
</a>
</div>
<div class="tab-content mt-3 p-3 bg-light">
<div class="tab-pane active"
id="ds" role="tabpanel">
A data structure is a group of data elements
that provides the easiest way to store and
perform different actions on the data of the
computer. A data structure is a particular
way of organizing data in a computer so that
it can be used effectively.
</div>
<div class="tab-pane" id="algo" role="tabpanel">
The word Algorithm means ” A set of finite rules
or instructions to be followed in calculations
or other problem-solving operations ” Or ”
A procedure for solving a mathematical problem
in a finite number of steps that frequently
involves recursive operations”
</div>
<div class="tab-pane" id="bs" role="tabpanel">
Bootstrap is a free and open-source collection
of CSS and JavaScript/jQuery code used for
creating dynamic websites layout and
web applications.
</div>
<div class="tab-pane" id="cpp" role="tabpanel">
C++ is a general-purpose programming language
and is widely used nowadays for competitive
programming. It has imperative, object-oriented
and generic programming features.
</div>
</div>
</div>
<br>
<button class="btn btn-danger" id="disposeAlgoBtn">
Dispose Algo Tab
</button>
<button class="btn btn-danger" id="disposeCPPBtn">
Create and Get instance, and Dispose cpp Tab
</button>
<script>
const algoEl = document.getElementById('algo');
const algoElTab = new bootstrap.Tab(algoEl)
const cppEl = document.getElementById('cpp');
const disAlgoBtn =
document.getElementById('disposeAlgoBtn')
const disCPPBtn =
document.getElementById('disposeCPPBtn')
disAlgoBtn.addEventListener('click', function () {
// Instance before disposing
console.log(algoElTab);
algoElTab.dispose()
// Instance after disposing
console.log(algoElTab);
})
disCPPBtn.addEventListener('click', function () {
// Creating a new Instance for CPP Tab
let cppInstance =
bootstrap.Tab.getOrCreateInstance(cppEl);
// Instance before disposing
console.log(cppInstance);
cppInstance.dispose()
// Instance after disposing
console.log(cppInstance);
})
</script>
</body>
</html>
Output:
Similar Reads
Bootstrap 5 List group Active items Bootstrap 5 provides the List Group Active feature in which items are stored in form of a list. List groups are a flexible and powerful component for displaying a series of content. The List Group Active feature is used to indicate the currently active selection. List group Active items classes: .ac
2 min read
Bootstrap 5 List group Disabled items Bootstrap 5 provides the List Group disabled items feature in which items are stored in form of a list. List groups are a flexible and powerful component for displaying a series of content. The List Group Disabled items feature is used to indicate the item is currently disabled. List Group Disabled
2 min read
Bootstrap 5 List group Links and buttons Bootstrap 5 provides the List Group Links and Buttons items feature in which items are actionable and stored in form of a list. List groups are a flexible and powerful component for displaying a series of content. The List Group Links and Buttons items feature is used to indicate the item is current
2 min read
Bootstrap 5 List group Flush Bootstrap 5 provides the List Group Flush feature in which items are stored in the form of a list. List groups are a flexible and powerful component for displaying a series of content. The List Group Flush feature is used to remove borders and rounded corners around the items on the list. List group
2 min read
Bootstrap 5 List group Numbered Bootstrap 5 List Group Numbered is one of the capabilities offered by List Group in Bootstrap 5, which is used to keep items in the form of a list and display them sequentially through the use of numbers. List Group Numbered Classes: list-group-item: This class is used to indicate and add the items
2 min read
Bootstrap 5 List group Horizontal Bootstrap 5 List group Horizontal facilitates to modification & alignment of the structure of the list group items from vertical to horizontal, across all breakpoints, by implementing the .list-group-horizontal class. In order to create a list group horizontal that starts with the min-width of t
2 min read
Bootstrap 5 List group Contextual classes Bootstrap 5 List group Contextual classes are used to style list-group-items with different backgrounds and colors. Bootstrap 5 List group Contextual Used Classes: list-group-item-primary: For blue color styling of the list itemlist-group-item-success: For green color styling of the list itemlist-gr
2 min read
Bootstrap 5 List group with badges Bootstrap 5 List group with badges can be used to add badges to the list group item to indicate the count of objects. List group With badges Classes: No special classes are used in the List group With badges. You can customize the list using .badge classes and style them with flex. Bootstrap 5 List
2 min read
Bootstrap 5 List group Custom content Bootstrap 5 List Group Custom content allows us to use HTML inside the list, here, the term "Custom Content" refers to HTML, therefore any HTML elements can be used inside, including anchor tags, paragraph tags, divs, photos, and many more.Bootstrap 5 List Group Custom content Classes: There is no p
2 min read
Bootstrap 5 List group Checkboxes and radios Bootstrap 5 List group Checkboxes and radios use .list-group and .list-group-item classes to create a list of items. The .list-group class is used with <ul> element and the .list-group-item is used with <li> element. Then create the checkbox and radios in the input element using the type
2 min read