Created
February 15, 2024 05:50
-
-
Save makotom/83922a11cf735cabeb165ed1d1d84f10 to your computer and use it in GitHub Desktop.
Dynamic generation of HTML anchors (to test Intents)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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