• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: The event of second set of dynamically created buttons refuses to work

Resolved: The event of second set of dynamically created buttons refuses to work

0
By Isaac Tonny on 16/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I wrote up a code that displays food items on the screen by creating elements of varied tags dynamically. And I’ve placed the entire process in one function called displayMenuItems. Now the first set of dynamically created buttons (i.e ‘add-btn’ buttons), when I add an event to them, the event will fire without a hitch when clicked. However the second set of dynamically created buttons (i.e ‘delete-btn’ buttons), when an event is added to them, the event will not fire when clicked. I’ve no idea why this complication arises when the code of the second set of buttons is similar to the first set of buttons. Could you fix this problem, I would really appreciate it?

Answer:

delete-btns elements are not generated initially, but your events are only added for the first time, so that’s why all your delete events are not applied when you add them into DOM.
I’d suggest that you should add an event directly on the newly added delete button every time.


If you have better answer, please add a comment about this, thank you!

html javascript
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to make statement case insensitive when uploading a dta file with specified columns?

27/03/2023

Resolved: Sort dataframe columns value by close it to another column

27/03/2023

Resolved: PostgreSQL resample 1 minute OHLCV candle data into 5 minute OHLCV candle data

27/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.