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 Modifying Elements

Mike Gugliuzza
Mike Gugliuzza
8,497 Points

Set the text content of the a tag to be the value stored in the variable inputValue

I'm really not sure why this is so difficult for me- am i not understanding the instructions correctly? Thanks!

app.js
let inputValue = document.getElementById('linkName').value;
let a = document.getElementById('a');
a.textContent = inputValue;
index.html
<!DOCTYPE html>
<html>
    <head>
        <title>DOM Manipulation</title>
    </head>
    <link rel="stylesheet" href="style.css" />
    <body>
        <div id="content">
            <label>Link Name:</label>
            <input type="text" id="linkName">
            <a id="link" href="https://teamtreehouse.com"></a>
        </div>
        <script src="app.js"></script>
    </body>
</html>

3 Answers

Elad Ohana
Elad Ohana
24,456 Points

Hi Mike,

Your code shows

let a = document.getElementById('a');

the 'a' is the tag name... what is the id name?

Let me know if you need more help.

Elad.

Mike Gugliuzza
Mike Gugliuzza
8,497 Points

Hi Elad, Thanks for the reply! That solves one of my problems but now I have this:

let inputValue = document.getElementById('linkName').value; let a = document.getElementsByTagName('a').textContent; a = inputValue;

and it still does not seem to be working..

Elad Ohana
Elad Ohana
24,456 Points

Hi Mike,

Using 'getElementsByTagName' will give you an array, which means you'd have to use bracket notation -> []. Your code was actually really close the first time. My comment was to replace the 'a' with the id-name of the <a> tag, which is in the HTML. Your first attempt actually had the right code otherwise.

Elad.

Mike Gugliuzza
Mike Gugliuzza
8,497 Points

Got it.. that was a great help- thanks so much!!

Antonio De Rose
Antonio De Rose
20,885 Points
//I tried all of below, gives me an error still

document.querySelector('a').innerHTML = 'sdsdsds';
"sdsdsds"
document.querySelector('a').textContent = 'sdsdsdsndmf';
"sdsdsdsndmf"
document.getElementById('link').textContent = 'sdsdsds';
"sdsdsds"
document.getElementsByTagName('a')[0].textContent = 'dswwewewewe'
"dswwewewewe"