Lecture Notes of Class 17: Tooltips and Popovers
Overview:
In web
development, tooltips and popovers are commonly used to provide additional
information to the user when they hover over or click on an element, such as a
button or a link. These components help improve user experience by offering
contextual details without overcrowding the interface.
- Tooltips
are small pop-up boxes that appear when a user hovers over an element.
They are typically used to display brief descriptions or hints.
- Popovers
are more advanced versions of tooltips. They can display richer content,
such as text, images, or even complex HTML elements, and are often
triggered by a click or hover.
This
class will focus on how to use Bootstrap's tooltip and popover components to
enhance the interactivity of your web pages.
1.
Tooltips
What are
Tooltips?
Tooltips
are small messages that appear when a user hovers over an element. They can
provide additional information about the element’s function or purpose.
Tooltips are often used in buttons, form fields, icons, and links.
How to
Add Tooltips in Bootstrap:
Bootstrap
provides a built-in component for tooltips that is easy to use. Follow these
steps to add tooltips to elements.
Step 1:
Include Bootstrap in your Project
To use
Bootstrap’s tooltip component, you need to include Bootstrap’s CSS and
JavaScript files. You can do this by including the CDN links in the <head>
of your HTML
file.
html
<!-- Include Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Include Bootstrap JS and Popper.js (required for tooltips and popovers) -->
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.min.js"></script>
Step 2:
Add Tooltip to an Element
Add the data-bs-toggle="tooltip"
attribute to the HTML element that will display the tooltip. The tooltip text
is specified using the title
attribute.
html
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="Click to submit the form">
Submit
</button>
In this
example:
- The
data-bs-toggle="tooltip"
tells Bootstrap to display the tooltip. - The
title="Click to submit the form"
defines the text that will appear inside the tooltip.
Step 3:
Initialize the Tooltip
You must
initialize the tooltip using JavaScript after the page loads. You can do this
using the following script:
html
<script>
// Initialize all tooltips
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
This code
finds all elements with the data-bs-toggle="tooltip"
attribute and applies the tooltip functionality to them.
Example
with Button:
html
<button type="button" class="btn btn-info" data-bs-toggle="tooltip" title="This is an info button">
Info
</button>
Customizing
Tooltips:
You can
customize tooltips using options like:
- placement:
Controls the position of the tooltip (top, bottom, left, right).
- trigger:
Defines how the tooltip is triggered (hover, click, focus, etc.).
html
<button type="button" class="btn btn-danger" data-bs-toggle="tooltip" title="Delete item" data-bs-placement="left">
Delete
</button>
2.
Popovers
What are
Popovers?
Popovers
are similar to tooltips but are more flexible. They allow you to display more
complex content (such as images, forms, or other HTML elements) inside a
pop-up. Popovers are typically triggered by a click event.
How to
Add Popovers in Bootstrap:
Just like
tooltips, popovers can be added using the Bootstrap framework, with the
following steps.
Step 1:
Add Popover to an Element
To create
a popover, you use the data-bs-toggle="popover"
attribute on the element, and the data-bs-content
attribute holds the content of the popover.
html
<button type="button" class="btn btn-secondary" data-bs-toggle="popover" title="Popover title" data-bs-content="Some popover content here.">
Click me for popover
</button>
Step 2:
Initialize the Popover
Popovers
also need to be initialized using JavaScript. After the page loads, add this
script to enable the popover functionality:
html
<script>
// Initialize all popovers
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
Example
with Popover:
html
<button type="button" class="btn btn-warning" data-bs-toggle="popover" title="Popover Example" data-bs-content="This is an example of a popover with detailed content">
Show Popover
</button>
Customizing
Popovers:
Popovers
offer various options for customization:
- placement:
You can control where the popover will appear (top, bottom, left, right).
- trigger:
Define how the popover is triggered (hover, click, focus, etc.).
- content:
You can include more complex HTML content inside a popover.
html
<button type="button" class="btn btn-success" data-bs-toggle="popover" title="HTML Content Popover" data-bs-content="<b>This is bold text</b> <br> <i>This is italicized text</i>">
Popover with HTML
</button>
This
example shows how to include HTML content inside a popover (bold and italic
text).
Lab
Tasks:
Task 1:
Add Tooltips to Buttons and Links
1.
Create a button that displays a tooltip
when hovered over, describing its function.
2.
Create a link that shows additional
information when the user hovers over it.
Example:
html
<button type="button" class="btn btn-success" data-bs-toggle="tooltip" title="This button saves your work">
Save
</button>
<a href="#" data-bs-toggle="tooltip" title="Click to visit our homepage">Visit Home
</a>
Task 2:
Use Popovers to Display Additional Information on Hover
1.
Add a button that displays a popover
when clicked, containing extra details or instructions.
2.
Customize the popover to display more
complex content, such as images or formatted text.
Example:
html
<button type="button" class="btn btn-info" data-bs-toggle="popover" title="Popover Example" data-bs-content="Here is more detailed information on how to use this tool.">
Learn More
</button>
Conclusion:
- Tooltips
and popovers are useful components that help enhance the user experience
by providing additional information when needed.
- Tooltips
are typically used for brief descriptions or hints and are shown when the
user hovers over an element.
- Popovers
are more complex, allowing for richer content, and can be triggered by
both hover and click events.
With this
knowledge, you can make your website more interactive and user-friendly by
displaying helpful tooltips and popovers.
You
said:
WRITE 10 ASSIGNMENTS
FROM ABOVE CONCEPT WITH STEP BY STEP SOLUTIONS with proper explanation
ChatGPT
said:
Here are 10
assignments based on the concepts of tooltips and popovers
in Bootstrap, along with step-by-step solutions and explanations. These
assignments are designed for beginner-level students.
Assignment
1: Create a Tooltip for a Button
Task: Add a tooltip to a button that
appears when the user hovers over the button, explaining the button's purpose.
Solution:
1.
HTML Structure: Create a button element with a tooltip.
html
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="Click to submit your form">
Submit
</button>
2.
JavaScript for Tooltip: Add the following JavaScript to initialize the
tooltip:
html
<script>
// Initialize all tooltips
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
Assignment
2: Add Tooltip to a Link
Task: Add a tooltip to a link that shows
extra information when the user hovers over it.
Solution:
1.
HTML Structure: Add a link with the data-bs-toggle="tooltip"
and a title
attribute.
html
<a href="https://www.example.com" data-bs-toggle="tooltip" title="Go to Example Website">
Visit Example
</a>
2.
JavaScript for Tooltip:
html
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
Assignment
3: Create Multiple Tooltips
Task: Add tooltips to multiple elements
on a webpage, such as buttons and icons.
Solution:
1.
HTML Structure: Add multiple buttons and links with tooltips.
html
<button type="button" class="btn btn-warning" data-bs-toggle="tooltip" title="Warning button">
Warning
</button>
<button type="button" class="btn btn-success" data-bs-toggle="tooltip" title="Success button">
Success
</button>
<a href="#" data-bs-toggle="tooltip" title="Information link">Information
</a>
2.
JavaScript for Tooltip:
html
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
Assignment
4: Create a Popover for a Button
Task: Create a popover that displays
detailed content when the user clicks a button.
Solution:
1.
HTML Structure: Add a button with data-bs-toggle="popover"
and data-bs-content
.
html
<button type="button" class="btn btn-danger" data-bs-toggle="popover" title="Popover Title" data-bs-content="This is a detailed description.">
Click for Details
</button>
2.
JavaScript for Popover:
html
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
Assignment
5: Customizing Popovers with HTML Content
Task: Create a popover with rich HTML
content, such as bold and italic text.
Solution:
1.
HTML Structure: Create a button that triggers a popover with HTML content.
html
<button type="button" class="btn btn-info" data-bs-toggle="popover" title="HTML Content Popover" data-bs-content="<b>This is bold text</b> <br> <i>This is italicized text</i>">
Show Popover
</button>
2.
JavaScript for Popover:
html
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
Assignment
6: Change Popover Placement
Task: Display a popover on the right side
of a button when clicked.
Solution:
1.
HTML Structure: Add data-bs-placement="right"
to change the placement of the popover.
html
<button type="button" class="btn btn-secondary" data-bs-toggle="popover" title="Right Placement" data-bs-content="This popover appears on the right" data-bs-placement="right">
Click Me
</button>
2.
JavaScript for Popover:
html
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
Assignment
7: Tooltip with Different Triggers
Task: Create a tooltip that triggers on
click instead of hover.
Solution:
1.
HTML Structure: Add data-bs-trigger="click"
to the tooltip.
html
<button type="button" class="btn btn-primary" data-bs-toggle="tooltip" title="This is a clickable tooltip" data-bs-trigger="click">
Click Me
</button>
2.
JavaScript for Tooltip:
html
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
Assignment
8: Use Tooltips with Images
Task: Add a tooltip to an image element
to describe the image when hovered.
Solution:
1.
HTML Structure: Add an image element with a tooltip.
html
<img src="image.jpg" alt="Example Image" data-bs-toggle="tooltip" title="This is an example image">
2.
JavaScript for Tooltip:
html
<script>
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
</script>
Assignment
9: Add Multiple Popovers to a Page
Task: Add multiple popovers on different
elements on the page.
Solution:
1.
HTML Structure: Add multiple buttons, each with its own popover.
html
<button type="button" class="btn btn-primary" data-bs-toggle="popover" title="First Popover" data-bs-content="This is the first popover.">
Button 1
</button>
<button type="button" class="btn btn-secondary" data-bs-toggle="popover" title="Second Popover" data-bs-content="This is the second popover.">
Button 2
</button>
2.
JavaScript for Popover:
html
<script>
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
Assignment
10: Tooltip and Popover Together
Task: Create a button with both a tooltip
and a popover. The tooltip should appear when the user hovers, and the popover
should appear when the user clicks.
Solution:
1.
HTML Structure: Add both tooltip and popover to a single button.
html
<button type="button" class="btn btn-success" data-bs-toggle="tooltip" title="This is a tooltip" data-bs-toggle="popover" title="Popover Title" data-bs-content="This is a popover">
Tooltip and Popover
</button>
2.
JavaScript for Tooltip and Popover:
html
<script>
// Initialize all tooltips and popovers
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.forEach(function (tooltipTriggerEl) {
new bootstrap.Tooltip(tooltipTriggerEl);
});
var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]'));
popoverTriggerList.forEach(function (popoverTriggerEl) {
new bootstrap.Popover(popoverTriggerEl);
});
</script>
These
assignments will help students understand the basics of using tooltips and
popovers in web development with Bootstrap, including practical examples and
variations.
You
said:
WRITE 50 no of MCQs
only FROM ABOVE CONCEPT with explanation
ChatGPT
said:
Here are 50
multiple-choice questions (MCQs) based on tooltips
and popovers using Bootstrap, with detailed explanations for
each correct answer.
MCQ
1: What is the primary purpose of a tooltip in Bootstrap?
A) To
show an image on hover
B) To display additional information on hover
C) To change the background color of an element
D) To show a list of items
Answer: B) To display additional
information on hover
Explanation: Tooltips provide small pop-up boxes with
information when the user hovers over an element.
MCQ
2: Which attribute is used to specify the text for a tooltip in Bootstrap?
A) data-bs-tooltip
B) title
C) data-bs-content
D) data-bs-title
Answer: B) title
Explanation: The title
attribute is used to specify the text content that appears in the tooltip.
MCQ
3: How do you trigger a tooltip in Bootstrap?
A) By
clicking the element
B) By hovering over the element
C) By typing into the element
D) By double-clicking the element
Answer: B) By hovering over the element
Explanation: Tooltips are triggered when the user hovers over
the element.
MCQ
4: Which JavaScript method is used to initialize a tooltip in Bootstrap?
A) new bootstrap.Tooltip()
B) initializeTooltip()
C) new Tooltip()
D) bootstrap.tooltip()
Answer: A) new
bootstrap.Tooltip()
Explanation: The new
bootstrap.Tooltip()
method initializes tooltips in Bootstrap.
MCQ
5: What is the default trigger event for tooltips in Bootstrap?
A) Mouse
click
B) Hover
C) Focus
D) Double-click
Answer: B) Hover
Explanation: By default, tooltips in Bootstrap are triggered
on hover.
MCQ
6: Which attribute is used to specify the placement of a tooltip?
A) data-bs-placement
B) data-placement
C) tooltip-placement
D) position
Answer: A) data-bs-placement
Explanation: The data-bs-placement
attribute is used to specify where the tooltip will appear relative to the
target element (top, bottom, left, or right).
MCQ
7: Which Bootstrap class is used to style a button with a tooltip?
A) btn-tooltip
B) btn-primary
C) btn-hover
D) btn-style
Answer: B) btn-primary
Explanation: The btn-primary
class is used to style buttons in Bootstrap.
MCQ
8: What is the purpose of the data-bs-toggle="popover"
attribute in Bootstrap?
A) To
create a tooltip
B) To create a popover
C) To create a dropdown menu
D) To apply a button style
Answer: B) To create a popover
Explanation: The data-bs-toggle="popover"
attribute is used to trigger a popover when clicked.
MCQ
9: How can you customize the content of a popover in Bootstrap?
A) Using
the data-bs-tooltip
attribute
B) Using the data-bs-content
attribute
C) Using the title
attribute
D) Using the data-bs-toggle
attribute
Answer: B) Using the data-bs-content
attribute
Explanation: The data-bs-content
attribute is used to specify the content of a popover in Bootstrap.
MCQ
10: How do you initialize a popover in Bootstrap?
A) new bootstrap.Popover()
B) initializePopover()
C) popover()
D) new Popover()
Answer: A) new
bootstrap.Popover()
Explanation: The new
bootstrap.Popover()
method is used to initialize popovers in
Bootstrap.
MCQ
11: Which event triggers a popover by default in Bootstrap?
A) Click
B) Hover
C) Focus
D) Double-click
Answer: A) Click
Explanation: By default, popovers are triggered when the user
clicks the element.
MCQ
12: What is the default placement of a popover in Bootstrap?
A) Top
B) Bottom
C) Left
D) Right
Answer: B) Bottom
Explanation: By default, popovers are placed below the target
element (bottom).
MCQ
13: Which Bootstrap class is used to create a danger button with a popover?
A) btn-danger
B) btn-warning
C) btn-primary
D) btn-dark
Answer: A) btn-danger
Explanation: The btn-danger
class is used to create a red (danger) button in Bootstrap.
MCQ
14: How can you display HTML content in a popover in Bootstrap?
A) Using
the data-bs-html="true"
attribute
B) Using the data-bs-content
attribute
C) Using the html
attribute
D) Using the data-html="true"
attribute
Answer: A) Using the data-bs-html="true"
attribute
Explanation: The data-bs-html="true"
attribute allows HTML content inside a popover.
MCQ
15: How can you hide a tooltip after showing it in Bootstrap?
A) tooltip.hide()
B) tooltip.remove()
C) tooltip.dispose()
D) tooltip.close()
Answer: C) tooltip.dispose()
Explanation: The tooltip.dispose()
method is used to remove the tooltip instance and stop showing it.
MCQ
16: What does the data-bs-trigger="focus"
attribute do?
A) It
triggers the tooltip when the element gains focus
B) It triggers the tooltip when the element is clicked
C) It triggers the tooltip when the element is hovered
D) It disables the tooltip
Answer: A) It triggers the tooltip when the
element gains focus
Explanation: The data-bs-trigger="focus"
attribute triggers the tooltip when the element receives focus, typically on
form inputs.
MCQ
17: Which of the following methods can be used to open a popover manually in
Bootstrap?
A) popover.show()
B) popover.open()
C) popover.trigger()
D) popover.activate()
Answer: A) popover.show()
Explanation: The popover.show()
method is used to manually show a popover.
MCQ
18: How can you change the placement of a popover to the top in Bootstrap?
A) data-bs-placement="top"
B) data-bs-position="top"
C) popover-placement="top"
D) popover-top="true"
Answer: A) data-bs-placement="top"
Explanation: The data-bs-placement="top"
attribute is used to set the popover to appear on top of the element.
MCQ
19: What is the purpose of the data-bs-title
attribute in Bootstrap?
A) To
specify the content of the tooltip
B) To specify the title of a popover
C) To specify the class of the button
D) To specify the trigger for the tooltip
Answer: B) To specify the title of a
popover
Explanation: The data-bs-title
attribute is used to set the title of the popover.
MCQ
20: What does the data-bs-toggle="tooltip"
attribute do?
A)
Initializes the tooltip
B) Toggles the tooltip visibility
C) Triggers the popover
D) Adds the tooltip to the element
Answer: A) Initializes the tooltip
Explanation: The data-bs-toggle="tooltip"
attribute is used to initialize a tooltip on the element.
MCQ
21: Which of the following is a valid popover trigger event?
A) focus
B) hover
C) click
D) All of the above
Answer: D) All of the above
Explanation: Popovers can be triggered by various events such
as focus
, hover
, and click
, depending on the
configuration.
MCQ
22: How do you disable a tooltip in Bootstrap?
A) data-bs-disable="true"
B) tooltip.disable()
C) data-bs-enabled="false"
D) tooltip.dispose()
Answer: D) tooltip.dispose()
Explanation: The tooltip.dispose()
method is used to disable and remove the tooltip from an element.
MCQ
23: Which method is used to toggle the visibility of a popover manually?
A) popover.toggle()
B) popover.show()
C) popover.hide()
D) popover.switch()
Answer: A) popover.toggle()
Explanation: The popover.toggle()
method can be used to show or hide a popover manually.
MCQ
24: What is the purpose of the data-bs-container
attribute in Bootstrap?
A) To set
the parent container for the tooltip
B) To specify the position of the tooltip
C) To specify the element type for the tooltip
D) To apply the style for the tooltip
Answer: A) To set the parent container for
the tooltip
Explanation: The data-bs-container
attribute is used to specify the container where the tooltip will be appended.
MCQ
25: Which method is used to initialize a tooltip on multiple elements in
Bootstrap?
A) new bootstrap.Tooltip(selector)
B) tooltip.init(selector)
C) tooltip()
D) new Tooltip()
Answer: A) new
bootstrap.Tooltip(selector)
Explanation: The new
bootstrap.Tooltip(selector)
method is used to initialize tooltips
on multiple elements using a selector.
MCQ
26: Which of the following Bootstrap class is used for a popover with large
content?
A) popover-lg
B) popover-extended
C) popover-xl
D) None of the above
Answer: D) None of the above
Explanation: Bootstrap does not provide a specific class for
large popovers. You would need to customize the size using CSS.
MCQ
27: How do you disable automatic hiding of popovers when clicking outside?
A) data-bs-close="false"
B) data-bs-auto-close="false"
C) data-bs-dismiss="false"
D) data-bs-close="off"
Answer: B) data-bs-auto-close="false"
Explanation: To prevent the automatic closing of a popover
when clicking outside, you can set data-bs-auto-close="false"
.
MCQ
28: What happens when the data-bs-html="true"
attribute is set for a tooltip?
A) It
allows HTML content to be displayed inside the tooltip
B) It disables the tooltip
C) It adds a tooltip to all elements
D) It changes the placement of the tooltip
Answer: A) It allows HTML content to be
displayed inside the tooltip
Explanation: Setting data-bs-html="true"
allows HTML to be used within the tooltip content.
MCQ
29: How do you make a popover automatically open when the page loads?
A) popover.open()
B) data-bs-show="true"
C) popover.trigger()
D) popover.auto()
Answer: B) data-bs-show="true"
Explanation: Setting data-bs-show="true"
automatically opens the popover when the page loads.
MCQ
30: Which option sets the maximum width of a popover in Bootstrap?
A) max-width
B) popover-max-width
C) popover-width
D) data-bs-width
Answer: A) max-width
Explanation: You can customize the width of a popover using
the CSS property max-width
.
MCQ
31: What should be included in the data-bs-toggle
attribute to initialize a popover?
A) popover
B) tooltip
C) collapse
D) modal
Answer: A) popover
Explanation: The data-bs-toggle="popover"
initializes the popover functionality.
MCQ
32: Which of the following Bootstrap class is used to display tooltips for the
first time after clicking?
A) btn-clickable
B) data-bs-trigger="click"
C) tooltip-click
D) tooltip-enable
Answer: B) data-bs-trigger="click"
Explanation: Setting data-bs-trigger="click"
causes the tooltip to appear when clicked.
MCQ
33: How do you close a popover in Bootstrap?
A) popover.hide()
B) popover.remove()
C) popover.close()
D) popover.dismiss()
Answer: A) popover.hide()
Explanation: The popover.hide()
method closes the popover.
MCQ
34: What is the default position of tooltips in Bootstrap?
A) Bottom
B) Top
C) Right
D) Left
Answer: B) Top
Explanation: By default, tooltips in Bootstrap are positioned
at the top of the target element.
MCQ
35: Which attribute is used to enable/disable the trigger for a tooltip?
A) data-bs-disabled
B) data-bs-disable
C) data-bs-trigger
D) data-bs-enable
Answer: C) data-bs-trigger
Explanation: The data-bs-trigger
attribute is used to specify what event should trigger the tooltip.
MCQ
36: Which of the following JavaScript events is typically used to show a
popover?
A)
Mouseenter
B) Mouseleave
C) Focus
D) All of the above
Answer: D) All of the above
Explanation: Popovers can be triggered by various events like mouseenter
, mouseleave
, and focus
depending on the
setup.
MCQ
37: How do you close the tooltip programmatically in Bootstrap?
A) tooltip.hide()
B) tooltip.close()
C) tooltip.remove()
D) tooltip.dispose()
Answer: A) tooltip.hide()
Explanation: The tooltip.hide()
method is used to hide a tooltip programmatically.
MCQ
38: How do you initialize multiple tooltips on elements using JavaScript?
A) new bootstrap.Tooltip('.selector')
B) tooltip.init('.selector')
C) tooltip()
on('.selector')
D) initialize('.selector')
Answer: A) new
bootstrap.Tooltip('.selector')
Explanation: This initializes tooltips for all elements
matching the selector.
MCQ
39: What is the correct HTML markup for a popover in Bootstrap?
A) <button
data-bs-toggle="popover" title="Popover"
data-bs-content="Content">Click me</button>
B) <div
data-bs-toggle="popover" title="Popover"
data-bs-content="Content"></div>
C) <span
data-bs-toggle="popover" title="Popover"
data-bs-content="Content"></span>
D) All of the above
Answer: D) All of the above
Explanation: All these elements can be used to create a
popover in Bootstrap.
MCQ
40: Which of the following is not an option for customizing popovers?
A) Title
B) Content
C) Background color
D) Placement
Answer: C) Background color
Explanation: The popover can be customized for title, content,
and placement, but background color needs to be customized with CSS.
MCQ
41: Which method is used to close a popover manually?
A) popover.close()
B) popover.remove()
C) popover.hide()
D) popover.dispose()
Answer: C) popover.hide()
Explanation: The popover.hide()
method is used to manually hide a popover.
MCQ
42: Which of the following is a valid Bootstrap class for a button with a
tooltip?
A) btn-tooltip
B) btn-hover
C) btn-primary
D) btn-active
Answer: C) btn-primary
Explanation: The btn-primary
class is used for styling buttons in Bootstrap.
MCQ
43: What happens when the data-bs-content
attribute is used with a popover?
A) It
adds a custom class to the popover
B) It sets the title of the popover
C) It specifies the content displayed in the popover
D) It sets the placement of the popover
Answer: C) It specifies the content
displayed in the popover
Explanation: The data-bs-content
attribute is used to define the content that appears inside the popover.
MCQ
44: How do you trigger a tooltip on a focus event?
A) data-bs-trigger="focus"
B) data-bs-trigger="hover"
C) tooltip-focus="true"
D) data-focus="true"
Answer: A) data-bs-trigger="focus"
Explanation: The data-bs-trigger="focus"
attribute is used to trigger the tooltip when the element gets focus.
MCQ
45: How do you create a custom style for a tooltip in Bootstrap?
A) By
overriding CSS styles for .tooltip
B) By using the data-bs-style
attribute
C) By using custom-tooltip
class
D) By using the tooltip-custom
attribute
Answer: A) By overriding CSS styles for .tooltip
Explanation: You can customize the appearance of tooltips by
overriding the default CSS styles applied to .tooltip
.
MCQ
46: How do you ensure that a tooltip is not cut off when placed near the edge
of the viewport?
A) Using
the overflow
property
B) Setting the boundary
attribute to viewport
C) Using data-bs-boundary="viewport"
D) Using tooltip-edge="true"
Answer: C) Using data-bs-boundary="viewport"
Explanation: The data-bs-boundary="viewport"
setting ensures that the tooltip will stay within the viewport, even near the
edges.
MCQ
47: Which of the following is the correct syntax to initialize a popover using
JavaScript?
A) new bootstrap.Popover(element)
B) new
bootstrap.Tooltip(element)
C) popover(element)
D) popover.initialize(element)
Answer: A) new
bootstrap.Popover(element)
Explanation: To initialize a popover using JavaScript, you use
the new
bootstrap.Popover(element)
method.
MCQ
48: How can you change the position of a tooltip?
A) By
setting data-bs-position
attribute
B) By using data-bs-placement
attribute
C) By using the tooltip-position
class
D) By setting tooltip-position="left"
Answer: B) By using data-bs-placement
attribute
Explanation: The data-bs-placement
attribute is used to define where the tooltip should appear relative to the
element (top, bottom, left, right).
MCQ
49: How do you enable HTML content in a Bootstrap tooltip?
A) data-bs-html="true"
B) data-bs-enable-html="true"
C) data-bs-allow-html="true"
D) tooltip-html="true"
Answer: A) data-bs-html="true"
Explanation: Setting data-bs-html="true"
allows you to use HTML content within the tooltip.
MCQ
50: Which of the following options is used to define the appearance of a
tooltip in Bootstrap?
A) data-bs-style
B) data-bs-class
C) data-bs-toggle
D) tooltip-class
Answer: B) data-bs-class
Explanation: The data-bs-class
attribute is used to specify the style of the tooltip (though in many cases you
would use custom classes).
No comments:
Post a Comment