Created
August 21, 2017 23:42
-
-
Save jeanpaulsio/e84de2b1381a816552080ef670da5df7 to your computer and use it in GitHub Desktop.
Appending List Items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript"> | |
window.onload=function() { | |
var el = document.getElementById('postComment').addEventListener('click', registerClickHandler); | |
function registerClickHandler() { | |
var inputValue = document.getElementById('comment').value; | |
var list = document.getElementById('commentList'); | |
if (inputValue) { | |
var listNode = document.createElement("LI"); | |
var textNode = document.createTextNode(inputValue); | |
listNode.appendChild(textNode); | |
list.appendChild(listNode); | |
document.getElementById('comment').value = ""; | |
} | |
} | |
} | |
</script> | |
<ul id='commentList'> | |
</ul> | |
<form> | |
<input type='text' id='comment'/> | |
<input type='button' id='postComment' value='Post'/> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment