0

I inserted a new row to my list and this is my code

 function newToDo() {
 var newTODoList = document.getElementById('toDoListInput');
 var newLine = document.createElement('li');
 var list = document.getElementById('list');
 newLine.textContent = newTODoList.value;
 newLine.class = 'newLineClass';
 list.prepend(newLine);

when I used appendchild instead of prepend my code didn't work correctly... what is diffrences between them?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
  • 1
    Does this answer your question? [JavaScript append and prepend vs jQuery append and prepend](https://stackoverflow.com/questions/45408796/javascript-append-and-prepend-vs-jquery-append-and-prepend) – Rush W. May 17 '20 at 10:19

1 Answers1

3

prepend add item frond of list. append add item end of list. In snipped there is an example

$('div')
    .append('<span>Append</span>')
    .prepend('<span>Prepend</span>')
    .before('<span>Before</span>')
    .after('<span>After</span>');
div {
  border:2px solid #bbb;
  padding:10px;
  margin:10px auto;
}

span {
  display:block;
  width:65px;
  font:bold 12px Arial,Sans-Serif;
  color:white;
  padding:5px 10px;
  background-color:gray;    
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>-------content---------</div>
mr. pc_coder
  • 16,412
  • 3
  • 32
  • 54