function updateElementProperties(elementId, action, className, attributeName, attributeValue) { const element = document.getElementById(elementId); if (!element) { console.error(`Element with ID '${elementId}' not found.`); return; } if (className) { switch (action) { case 'add': element.classList.add(className); break; case 'remove': element.classList.remove(className); break; case 'toggle': element.classList.toggle(className); break; default: console.warn('Invalid class action. Use 'add', 'remove', or 'toggle'.'); } } if (attributeName && attributeValue !== undefined) { element.setAttribute(attributeName, attributeValue); } else if (attributeName && attributeValue === null) { element.removeAttribute(attributeName); } } // Example usage: // updateElementProperties('myButton', 'add', 'btn-primary'); updateElementProperties('myButton', 'toggle', 'btn-secondary'); updateElementProperties('myButton', null, null, 'data-status', 'inactive'); updateElementProperties('myButton', null, null, 'disabled', ''); // Set a boolean attribute // To remove an attribute: // updateElementProperties('myButton', null, null, 'data-status', null); console.log(document.getElementById('myButton').outerHTML);