Displaying definitions from a live link

Say you got a field called Word:

<div id="def"></div>
<script>
(async () => {
  const data = await fetch(
    `https://api.allorigins.win/get?url=${encodeURIComponent(
      "https://www.ldoceonline.com/dictionary/{{Word}}"
    )}`
  ).then((response) => {
    if (response.ok) return response.json();
    throw new Error("Network response was not ok.");
  });
  const dummy = document.createElement("div");
  dummy.innerHTML = data.contents;
  document.getElementById("def").innerText =
    dummy.querySelector(".DEF").innerText;
})();
</script>
4 Likes