Skip to content

Instantly share code, notes, and snippets.

@jeanpaulsio
Created August 21, 2017 23:42
Show Gist options
  • Save jeanpaulsio/e84de2b1381a816552080ef670da5df7 to your computer and use it in GitHub Desktop.
Save jeanpaulsio/e84de2b1381a816552080ef670da5df7 to your computer and use it in GitHub Desktop.
Appending List Items
<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