code: function getHrefRec(element) {
      var href = element.getAttribute('href');
  
      if (href) {
          return href.replace(location.origin, '');
      }
  
      if (element.parentElement && element.parentElement !== document.body) {
          return getHrefRec(element.parentElement);
      }
  
      return null;
  }
docs: Search recursively href attribute value between given element and parents