Programmatically add label with URL

I am currently adding a label with URL called UAT Template based on the dropdown item select. The label should not be created if already exist.

  • the link is not open in the new tab

  • The label for some reason not created

      function AddURL(){
    
      let lblTemplate = document.getElementsByClassName("ard-FormField-description")[8];
      //Check if the lblTemplate contain word 'UAT Template location'
      if(lblTemplate.innerHTML !== '' && lblTemplate.innerHTML.toLowerCase().indexOf('UAT Template Location') > -1){
          if (lblTemplate.indexOf(lblTemplate) == -1) {
              // create anchor link element
              let link = document.createElement("a")
    
              // Create txt
              let txt = document.createTextNode("UAT Template Location")
    
              //append txt to anchor element
              link.appendChild(txt)
    
              // set the title
              link.title =" Click to UAT Template Location";
    
              // set the href property
              link.href = "https://gampoendev.com/:w:/r/teams/teamcollab/Shared%20Documents/Templates/";
              link.setAttribute('target','_blank');
    
              // get text to add link to
    
              lblTemplate.appendChild(link)
          }
          else {
              return;
          }
      }
    

    }