Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Select a Page Element By Its ID

There is a variable named button in app.js. Set its value to contain a reference to the button element in index.html wit

Hi everybody,

can you help me with this question? I tried in this way:

''' let button = document.getElementsById8'sayPhrase');'''

but I receive error!

What am i wrong?

Thanks

6 Answers

Tijo Thomas
Tijo Thomas
9,737 Points

You have the right idea, but you just added an extra letter. The code should be:

let button = document.getElementById("sayPhrase");

You need to remove the "s" from "getElementsById" since that's not an actual method.

FHATUWANI Dondry MUVHANGO
FHATUWANI Dondry MUVHANGO
17,796 Points

button = document.getElementById("sayPhrase");

that is the correct way of putting it........because if you try what Thomas said, it will give a an error because of the variable 'button' will be duplicated

I had this question too but my problem was I forgot to include the "", or '' around the id name.

let button = document.getElementById("sayPhrase");

This is the correct answer:

button = document.getElementById("sayPhrase");

Starky Paulino
seal-mask
.a{fill-rule:evenodd;}techdegree
Starky Paulino
Front End Web Development Techdegree Student 6,398 Points

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

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

Khalid Yousif
Khalid Yousif
2,785 Points

let button; let input; button = document.getElementById("sayPhrase"); button.addEventListener('click', () => { alert(input.value); });