after reviewing the code more, let me introduce you to 'event delegation'. this will let you simplify all the code for attaching events to the buttons. this works by attaching the event to a parent container, such as the div with class='right-content', that all the buttons will exist in, regardless of when they are created. you would then find which button has been clicked by testing an attribute value from the button, such as a class name. the code would look like -
document.addEventListener("DOMContentLoaded", function() {
console.log("✅ DOM fully loaded and parsed.");
// use event delegation for dynamically added elements (buttons)
// attach the event to a common parent element - class='right-content'
const buttonWrapper = document.querySelector('.right-content');
// add the click event to everything in the common element, now or in the future
buttonWrapper.addEventListener('click', function (event) {
// examine the className of the clicked element
console.log('target class: ',event.target.className);
switch(event.target.className)
{
case 'view-details-btn':
view_details(event.target);
break;
case 'change-status-btn':
openStatusModal(event.target);
break;
case 'update-notes-btn':
openNotesModal(event.target);
break;
case 'delete-btn':
deleteRenewal(event.target);
break;
case 'closeModal':
document.getElementById(event.target.getAttribute("data-modal-id")).style.display = "none";
break;
case 'confirmChangeStatus':
confirmChangeStatus(event.target);
break;
case 'confirmUpdateNotes':
confirmUpdateNotes(event.target);
break;
}
});
});