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 trialGreg Schudel
4,090 PointsValue? inputType? Element?
I'm on Javascript and the Dom course and the terminology is confusing me a bit.
I'm trying to figure out which of the terms used are specific to the index.html attribute names and which are globally used to do specific things within Javascript (i.e. textContent innerHTML, etc)
1.) An element is any HTML tag on the page correct? I know CSS/HTML, just being EXTRA sure.
2.) In the exercise using the following code:
let inputValue = document.getElementById('linkName').value;
let a = document.getElementById('a');
a.textContent = inputValue; /*can't this be written like this...
inputValue += a.textContent;
*/
Previous questions aside, what exactly is being accomplished? I don't see any 'behavior' or additional functionality added to the page whatsoever through this code? Am I getting ahead of myself?
1 Answer
cortneyltaylor
9,561 Points1) Yes, an element in JavaScript is basically any DOM element.
2a) What that code is doing is grabbing document.getElementById('linkName').value and setting document.getElementById('a').textContent to that of document.getElementById('linkName').value. It seems like the second getElementById() is trying to select an <a> tag instead of document.getElementById('a'). If that is the case, it should be using the getElementsByTagName() method instead.
2b) I don't think your suggestion would work. The first (line 3) is setting document.getElementById('a').textContent to equal document.getElementById('linkName').value; your suggestion would add document.getElementById('a').textContent to document.getElementById('linkName').value.
Greg Schudel
4,090 PointsGreg Schudel
4,090 PointsThank you for your help and love your image avatar! I should of thought of that.