UMD Web Utilities Library
    Preparing search index...

    Function wrapTextNodeInSpan

    • Wraps text nodes within links or buttons in span elements

      Finds text nodes that are direct children of links or buttons and wraps them in span elements. This is useful for styling or animation purposes.

      Parameters

      • element: HTMLElement | HTMLAnchorElement | HTMLButtonElement

        The element containing the link or button, or the link/button itself

      Returns HTMLElement | HTMLAnchorElement | HTMLButtonElement | undefined

      The target element (link or button), or undefined if not found

      const button = document.createElement('button');
      button.innerHTML = 'Click me';
      wrapTextNodeInSpan(button);
      // Result: <button><span>Click me</span></button>