GabeLinux

Web - 3 - 7

Jan 22nd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const body = document.querySelector('body')
  2.  
  3. function makeElement(element, parent, type) {
  4.   let newElement = document.createElement(element)
  5.   if (type != null) {
  6.     newElement.type = type
  7.   }
  8.  
  9.   parent.appendChild(newElement)
  10.  
  11.   return newElement
  12. }
  13.  
  14. let form = makeElement('form', body)
  15.  
  16. let input = makeElement('input', form, 'text')
  17.  
  18. let submit = makeElement('input', form, 'submit')
  19.  
  20. let output = makeElement('p', body)
  21.  
  22. form.addEventListener('submit', (event) => {
  23.   event.preventDefault()
  24.   output.innerHTML = input.value + '<br>' + output.innerHTML
  25.   input.value = ''
  26. })
Advertisement
Add Comment
Please, Sign In to add comment