The element to clone and clean
The cleaned clone of the element
const link = document.createElement('a');
link.href = 'https://example.com';
link.className = 'styled-link';
link.setAttribute('data-tracking', 'click-event');
const cleaned = cloneElementWithoutAttributes({ element: link });
// Result: <a href="https://example.com"></a>
// All attributes except href are removed
Creates a clean copy of an element, removing all attributes except href
Clones an element and strips all attributes except the href attribute, which is preserved for links. Useful for sanitizing copied elements.