Lesson 4 of 7
Read what the user types
An <input> stores what the user types in its value property — read it at click time, not before.
Careful: if you read value outside the click handler, you get the value from page load.
document.getElementById('copy').addEventListener('click', function () {
var name = document.getElementById('name').value;
document.getElementById('out').textContent = name;
});🎯 Your goal
On clicking the #copy button, read the value of the #name input and write it into the #out paragraph.
PRO lesson
This advanced chapter is part of CodeAge PRO. Unlock it to keep your adventure going.
Discover PRO →