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

Tony Brackins
Tony Brackins
28,236 Points

Help with manipulating DOM

Please help. I can't get the DOM to manipulate this input.

var test = document.getElementsByTagName("input")[9];

test returns: <input type=​"text" value=​"www.blahblah.com" size=​"50" name=​"WWWSiteURL" class=​"bullet">​…​</input>​

test.innerHTML = '<input type="text" value="test" size="50" name="WWWSiteURL" class="bullet">'; "<input type="text" value="test" size="50" name="WWWSiteURL" class="bullet">"

test returns: <input type=​"text" value=​"www.blahblah.com" size=​"50" name=​"WWWSiteURL" class=​"bullet">​…​</input>​

See, the input value should change to "test", but it stays as blah blah

Marcus Parsons

Hey Tony,

Can you dump the HTML and JavaScript you have into a Codepen at Codepen.io and then paste the URL for the codepen here? I'd like to see the full code so that I can see what's going on.

Tony Brackins
Tony Brackins
28,236 Points

Ok Marcus Parsons here's the link: http://codepen.io/raje101/pen/RPVYGX

I'm trying to change the field name "id" to have "test" as input.

1 Answer

Tony,

You can't change the innerHTML of an input element, but all you gotta do is target the input's value to change the text to "test". You can only change the innerHTML of a containing element, not the inside of the element itself.

var test = document.getElementsByTagName("input")[1];

test.value = "test";

No problem, Tony! If you need anything else, just holler at me!