<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
title
>
Bootstrap Scrollspy Refresh Example
</
title
>
<
meta
charset
=
"utf-8"
>
<
meta
name
=
"viewport"
content="
width
=
device
-width,
initial-scale
=
1
">
<
link
rel
=
"stylesheet"
href
=
<
script
src
=
</
script
>
</
head
>
<
body
class
=
"m-3"
>
<
nav
id
=
"navbar"
class="navbar fixed-top
navbar-light bg-light px-3">
<
a
class
=
"navbar-brand"
href
=
"#"
>
Navbar
</
a
>
<
ul
class
=
"nav nav-pills"
>
<
li
class
=
"nav-item"
>
<
a
class
=
"nav-link "
href
=
"#scrollspy-list-item1"
>
Item 1
</
a
>
</
li
>
<
li
class
=
"nav-item"
>
<
a
class
=
"nav-link"
href
=
"#scrollspy-list-item2"
>
Item 2
</
a
>
</
li
>
<
li
class
=
"nav-item"
>
<
a
class
=
"nav-link"
href
=
"#scrollspy-list-item3"
>
Item 3
</
a
>
</
li
>
<
li
class
=
"nav-item"
>
<
a
class
=
"nav-link"
href
=
"#scrollspy-list-item4"
>
Item 4
</
a
>
</
li
>
</
ul
>
</
nav
>
<
br
><
br
><
br
>
<
h1
class
=
"text-success text-center"
>GeeksforGeeks</
h1
>
<
div
data-bs-spy
=
"scroll"
data-bs-target
=
"#navbar-example2"
data-bs-offset
=
"50"
tabindex
=
"0"
>
<
div
id
=
"scrollspy-list-item1"
>
<
h4
>Item 1</
h4
>
<
p
>
HTML stands for HyperText Markup Language.
It is used to design web pages using the
markup language. HTML is the combination
of Hypertext and Markup language. Hypertext
defines the link between the web pages and
markup language defines the text document
within the tag that define the structure
of web pages.
</
p
>
</
div
>
<
div
id
=
"scrollspy-list-item2"
>
<
h4
>Item 2</
h4
>
<
p
>
we will see the HTML Basics by understanding
all the basic stuff of HTML coding. There
are various tags that we must consider and
include while starting to code in HTML.
These tags help in the organization and
basic formatting of elements in our script
or web pages. These step-by-step procedures
will guide you through the process of
writing HTML.
</
p
>
</
div
>
<
div
id
=
"scrollspy-list-item3"
>
<
h4
>Item 3</
h4
>
<
p
>
CSS (Cascading Style Sheets)is used to
apply styles to web pages. Cascading Style
Sheets are fondly referred to as CSS.
It is used to make web pages presentable.
The reason for using this is to simplify
the process of making web pages presentable.
It allows you to apply styles on web pages.
More importantly, it enables you to do this
independently of the HTML that makes up each
web page.
</
p
>
</
div
>
<
div
id
=
"scrollspy-list-item4"
>
<
h4
>Item 4</
h4
>
<
p
>
Java is one of the most popular and widely used
programming language and platform. A platform is an
environment that helps to develop and run programs
written in any programming language.
</
p
>
</
div
>
</
div
>
<
button
id
=
"toggle-section"
class
=
"btn btn-primary"
>
Toggle Section
</
button
>
<
script
>
// Initialize Scrollspy
let scrollSpy = new bootstrap.ScrollSpy(document.body, {
target: '#navbar'
});
// Add event listener to toggle-section button
let toggleSection2Btn =
document.getElementById('toggle-section');
toggleSection2Btn.addEventListener('click', function () {
// Toggle the display property of section4
let section2 =
document.getElementById('scrollspy-list-item4');
section2.style.display =
section2.style.display === 'none' ? 'block' : 'none';
alert('item 4 changed');
// Call refresh method to update Scrollspy
scrollSpy.refresh();
});
</
script
>
</
body
>
</
html
>