JavaScript JavaScript and the DOM Getting a Handle on the DOM Selecting by Id

Zaria Sellers
Zaria Sellers
Full Stack JavaScript Techdegree Student 3,536 Points

utton = document . getElementById("sayPhrase");

is button = document . getElementById("sayPhrase"); the correct varible or phrase

js/app.js
var button;
button = document.getElementById("sayPhrase");
var input;

button.addEventListener('click', () => {
  alert(input.value);
});
index.html
<!DOCTYPE html>
<html>
  <head>
    <title>Phrase Sayer</title>
  </head>
  <body>
    <p><input type="text" id="phraseText"></p>
    <p><button id="sayPhrase">Say Phrase</button></p>
    <script src="js/app.js"></script>
  </body>
</html>

1 Answer

Kuanyshbek Ospanov
Kuanyshbek Ospanov
11,369 Points

I don't understand your question, but here is an answer:

var button = document.getElementById('sayPhrase');
var input = document.getElementById('phraseText');

button.addEventListener('click', () => {
  alert(input.value);
});