Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Dynamic Button Feedback Example</title> <style> #feedback { color: blue; margin-top: 10px; } </style> </head> <body> <div id="buttonContainer"> <!-- Buttons can be added or removed dynamically --> <button>Action 1</button> <button>Action 2</button> </div> <div id="feedback"></div> <script> const buttonContainer = document.getElementById('buttonContainer'); const feedback = document.getElementById('feedback'); buttonContainer.addEventListener('click', function(event) { if (event.target.tagName === 'BUTTON') { feedback.textContent = 'Button clicked: ' + event.target.textContent; } }); </script> </body> </html>