UMD Web Utilities Library
    Preparing search index...

    Function cloneElementWithoutAttributes

    • 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.

      Parameters

      • element: { element: HTMLElement }

        The element to clone and clean

      Returns HTMLElement

      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