Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM Making Changes to the DOM Modifying Elements

MacKenzie Santiago
MacKenzie Santiago
5,084 Points

Where is the explanation in the lesson plan for adding .value or .textContent outside of the parenthese?

4.2 Challenge Task - Modifying Elements:

const inputValue = document.querySelector('input').value; document.querySelector('p').textContent = inputValue;

2 Answers

Steven Parker
Steven Parker
216,033 Points

That's simply a shortcut for the principles demonstrated in the Change Element Attributes video. It saves a line of code and an extra variable.

What you were asking about in your previous question could also be implemented on 2 lines like this:

const myInput = document.querySelector('input');
const inputValue = myInput.value;

The concept of using the membership operator directly on the result of calling a function is illustrated in other courses, and is commonly called "chaining".