Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <ul class="list">
    <li id="id1">Item 1: before</li>
    <li id="id2">Item 2: before</li>
    <li id="id3">Item 3: before</li>
    <li id="id4">Item 4: before</li>
  </ul>
</body>
</html>
 
function controlElems(cl){
  var nl = document.querySelectorAll(cl + ' > *');
  console.log(nl.length);
}
document.addEventListener("DOMContentLoaded", function() {
  
  var list = document.querySelector('.list');
  
  controlElems('.list');
  
  //
  var newElm = document.createElement('li');
  newElm.id = "id5";
  newElm.innerHTML ="Item 5: after";
  list.appendChild(newElm);
  
  
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers