UMD Web Utilities Library
    Preparing search index...

    Function createTextWithLink

    • Creates a text element containing a link (useful for headlines, titles, etc.)

      Creates a container element (paragraph by default) with an anchor link inside. The link opens in a new tab with security attributes by default.

      Parameters

      • text: {
            allowHTML?: boolean;
            ariaLabel?: string;
            containerTag?: keyof HTMLElementTagNameMap;
            openInNewTab?: boolean;
            text: string;
            url: string;
        }

        The link text content

      Returns HTMLElement | null

      Container element with link inside, or null if required params are missing

      // Basic headline with link (paragraph wrapper)
      const headline = createTextWithLink({
      text: 'Read the full story',
      url: 'https://example.com/article'
      });

      // Heading with link
      const headingLink = createTextWithLink({
      text: 'Article Title',
      url: '/articles/123',
      containerTag: 'h2',
      openInNewTab: false
      });

      // With accessibility label
      const accessibleLink = createTextWithLink({
      text: 'Learn more',
      url: '/about',
      ariaLabel: 'Learn more about our mission and values'
      });