javascript - My function won't add a paragraph to the document -
javascript - My function won't add a paragraph to the document -
i'm trying create button add together paragraph text input
http://jsfiddle.net/3gf7tqvo/
javascript:
function addparagraph() { var textinput = document.getelementbyid("pageinput"); var newparagraph = document.createelement("p"); newparagraph.textcontent = textinput; document.getelementbyid("updatediv").appendchild(newparagraph); } document.getelementbyid('a').onclick = addparagraph;
html:
<button id='a'>click me!</button> <input type="text" id="pageinput"> <div id='updatediv'></div>
ฺbut after hr of frustration, can't see why won't add together paragraph.
you made 2 little mistakes:
use textinput.value
instead of textinput
so:
newparagraph.textcontent = textinput.value;
write onclick
instead of onclick
so:
document.getelementbyid('a').onclick = addparagraph;
demo
javascript
Comments
Post a Comment