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!

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

How does one select an element by an HTML tag like <div> or <a>?

I am doing a challenge task in which I need to select a specific element. I know how to select that element by it's ID however treehouse wants me to select that Element by the <a> tag. Is it possible to do that? Or am I misunderstanding what the challenge wants?

var inputValue=document.getElementById('linkName').value;

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

2 Answers

Hi Ryan, you are really close on this one just a few issues: make sure textContent has a capital C, also you don't really need to use template literals for the variable because it's not in a string. Here's my solution:

var inputValue = document.getElementById('linkName').value;
document.getElementById('link').textContent = inputValue;

Thank you. That one capitalization typo was holding me up. I don't think I would have noticed it on my own.