Skip to content
Advertisement

In Django bootstrap project toast messages showing for the first card in loop element

I want to toast messages for all those cards. but it is showing for the first card only. I have attached a view of my page where I want to add a toast message to view the details of the card if a user is not logged in. I noob in Django and Javascript. this is a small part of my university project.

my page looks like this: https://i.stack.imgur.com/cYSPW.jpg

JavaScript
JavaScript

Advertisement

Answer

So here your problem comes from the id toastbtn. You have iterated the for loop and all the buttons in the cards got the same id but id unique for everyone so the id is added to the first card button only. Here one thing can be done remove the toastbtn id from the button and onclick attribute on the btn and pass the value the function call like shown below –

JavaScript

The showToast function is the same function u added in you js file Your JS file will look like this

JavaScript

HTML File

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement