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) Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

how to know which way round to write code inside a button.addEventListener?

button.addEventListener("click", function(){
p.textContent = input.value;

The above is correct, but at first i wrote :

button.addEventListener("click", function(){
input.value = p.textContent;
Although it didnt work how do i know which way round to write apart from trial and error? Is it best to think of it this way, start with the item that you want to change?

1 Answer

Cameron Childres
Cameron Childres
11,818 Points

Hi Jason,

The left side receives the value, the right side gives the value. Consider what would be logged in this situation:

let a = 1;
let b = 2;
a = b;

"Start with the item that you want to change" is a fair way to think of it. In your example you want p.textContent to receive the value from input.value, so p.textContent goes on the left and input.value goes on the right.