To include Bootstrap icons in your JavaScript code, first, you need to include the Bootstrap CSS in your HTML file. Then, you can use the Bootstrap icon classes in your JavaScript code.
Here's an example:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
var icon = document.createElement('i');
icon.classList.add('bi', 'bi-heart-fill');
document.body.appendChild(icon);
In this example, we create a new i
element, add the bi
and bi-heart-fill
classes to it to create a heart icon, and then append it to the body
element.
You can also customize the icon size and color by adding additional classes to the i
element. For example:
icon.classList.add('bi', 'bi-heart-fill', 'text-danger', 'fs-4');
In this example, we also add the text-danger
class to set the icon color to red, and the fs-4
class to set the icon size to 1.5rem.
Asked: 2023-06-04 08:08:19 +0000
Seen: 7 times
Last updated: Jun 04 '23