Skip to content

Instantly share code, notes, and snippets.

@makotom
Created February 15, 2024 05:50
Show Gist options
  • Save makotom/83922a11cf735cabeb165ed1d1d84f10 to your computer and use it in GitHub Desktop.
Save makotom/83922a11cf735cabeb165ed1d1d84f10 to your computer and use it in GitHub Desktop.
Dynamic generation of HTML anchors (to test Intents)
<!doctype html>
<html lang="en">
<meta charset="UTF-8">
<title>Anchor generator</title>
<script>
addEventListener('DOMContentLoaded', () => {
const form = document.querySelector('form#input');
const input = document.querySelector('input#url');
const div = document.querySelector('div#output');
form.addEventListener('submit', (evt) => {
evt.preventDefault();
if (input.value === '') {
return;
}
const pElem = document.createElement('p');
const aElem = document.createElement('a');
const aText = document.createTextNode(input.value);
aElem.href = input.value;
aElem.appendChild(aText);
pElem.appendChild(aElem);
div.appendChild(pElem);
});
input.addEventListener('click', (evt) => console.log);
});
</script>
<form id="input">
<label>URL: <input type="text" id="url"></label> <button type="submit">Run</button>
</form>
<div id="output"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment