I’m trying to create a new toast via javascript using the bootstrap 5 toasts
so basically I searched everywhere and nothing showed up, I do not want to toggle or trigger an existing toast, all I want is to create one and show it
there are no javascript methods to create one, in bootstrap documentation, there is only create an Instance to initialize an existing one, is there a way?
https://getbootstrap.com/docs/5.2/components/toasts/
I appreciate all answers
2
Answers
i ended up doing this
If anyone has a more efficient or effective method, feel free to share it.
The easiest way to completely create the toast with Javascript and not use an existing HTML element would be to use
document.createElement()
to create the HTML divs and then add the needed classes, as described here to it.If you want to get the following:
You would do this:
Here I added the created divs to the body, but of course they can also be added to other divs.