JSFiddle - React, Tailwind, and code Playground

by flyingbee2012

HTML

<a href="https://microsoft-my.sharepoint.com/personal/biwu_microsoft_com/Documents/Attachments/OWA%20CLP%20(1)(2)(12).pptx" id="OLK_Beautified_d9b7ba64-c436-7adb-4e40-bd0cc16c1847" class="OWAAutoLink _3iLgzr8un7L5GebClucrpV _1Bl3Epd8DW0Ci3uZDqSnP5" style="padding: 0px 1px; background-color: rgb(243, 242, 241); border-radius: 2px; user-select: all;" contenteditable="false" data-ogsc="">
  <!--owa-attachment-remove-on-send-start--><span style="font-size: 16pt;"><i data-icon-name="Edit" aria-hidden="true" class="_28V6s2qWpjnFBjP3O5_ZUO root-61"></i></span>
  <!--owa-attachment-remove-on-send-end--><img src="https://r3.res.outlook.com/owa/prem/images/pptx_16x16.png" alt="" role="presentation" style="width: 16px; height: 16px; vertical-align: middle; padding: 1px 2px 2px 0px;"><span style="font-size: 16pt;">OWA CLP (1)(2)(12).pptx</span>
  <!--owa-attachment-remove-on-send-start--><img alt="" role="presentation" src="" hidden="" style="width: 12px; height: 12px; vertical-align: top;">
  <!--owa-attachment-remove-on-send-end-->
</a>

TypeScript

function getLinkText(anchorElement: HTMLAnchorElement): string {
		debugger;
    let innerText = "";
    if (anchorElement == null || anchorElement.nodeName === "I") {
    	return "";
    }
    if (anchorElement.nodeName === '#text') {
      return anchorElement.innerText; 	
    }
    for (let i = 0; i < anchorElement.childNodes.length; i++) {
        innerText += getLinkText(anchorElement.childNodes[i]);
    }
    return innerText;
}


/*function getLinkText(anchorElement: HTMLAnchorElement): string {
    let innerText = "";
    for (let i = 0; i < anchorElement.childNodes.length; i++) {
    	const child = anchorElement.childNodes[i];
      if (child.nodeName != "I" && child.innerText != null) {
        innerText += child.innerText;
      }
    }
    return innerText;
}*/


const anchorElement = $('#OLK_Beautified_d9b7ba64-c436-7adb-4e40-bd0cc16c1847')[0];
//alert(anchorElement.innerText);
const txt = getLinkText(anchorElement);
alert(txt);