Skip to content

Instantly share code, notes, and snippets.

@alexramdesigner
Created November 19, 2018 13:38
Show Gist options
  • Save alexramdesigner/644e27d00ff068e46cab3710e475dabe to your computer and use it in GitHub Desktop.
Save alexramdesigner/644e27d00ff068e46cab3710e475dabe to your computer and use it in GitHub Desktop.
JavaScript label example // source https://jsbin.com/suricir
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>JavaScript label example</title>
<style>
p {
font-family: 'helvetica neue', helvetica, sans-serif;
letter-spacing: 1px;
text-transform: uppercase;
text-align: center;
border: 2px solid rgba(0,0,200,0.6);
background: rgba(0,0,200,0.3);
color: rgba(0,0,200,0.6);
box-shadow: 1px 1px 2px rgba(0,0,200,0.4);
border-radius: 10px;
padding: 3px 10px;
display: inline-block;
cursor: pointer;
}
</style>
</head>
<body>
<p>Player 1: Chris</p>
<script>
const para = document.querySelector('p');
para.addEventListener('click', updateName);
function updateName() {
let name = prompt('Enter a new name');
para.textContent = 'Player 1: ' + name;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment