JSFiddle - React, Tailwind, and code Playground

by oilvier

HTML

<!doctype html>
<html>
<body>
  <a href="#foo">Click Me</a>
  <br><br>
  <button id="submit">Submit</button>
</body>
</html>

JavaScript

document.getElementById('submit').onclick = function() {
  var href = document.querySelector('a').getAttribute('href').replace(/#/, "");
  alert(href);
}