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 trialTony Brackins
28,766 PointsHelp 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
Tony Brackins
28,766 PointsOk 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
Marcus Parsons
15,719 PointsTony,
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";
Tony Brackins
28,766 PointsThanks so much!!
Tony Brackins
28,766 PointsThanks so much!!
Marcus Parsons
15,719 PointsNo problem, Tony! If you need anything else, just holler at me!
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsHey 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.