Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

  1. Include the Bootstrap CSS in your HTML file:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  1. Use the Bootstrap icon classes in your JavaScript code:
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.