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>
   <li><a href="#">First</a></li>
   <li><a href="#">Second</a></li>
   <li><a href="#">Third</a></li>
</ul>
</body>
</html>
 
var anchors = document.querySelectorAll('ul li a');
console.log(anchors);
for (var i=0; i<anchors.length; ++i) {
  anchors[i].addEventListener('click', addList);
}
function addList(e) {
  var li = document.createElement('li');
  var a = document.createElement('a');
  a.href = '#';
  a.textContent = 'new item';
  a.addEventListener('click', addList);
  li.appendChild(a);
  e.target.parentNode.insertBefore(li, e.target.nextSibling);
}
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers