Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <button id="btn-add-child">Add New Child </button>
  <div id="parent">
     
  </div>
</body>
</html>
 
var currChild = 1;
function getChildDivHtml(id) {
  return '<div id="child' + currChild + '">Child ' + currChild + '<button class="btn-add-siblings">Add Siblings</button></div>'
}
$(document).ready(function() {
$('#btn-add-child').on('click', function() {
  $('div#parent').append(getChildDivHtml(currChild));
  currChild++;
});
  
  $('div#parent').on('click', '.btn-add-siblings', function() {
    $(this).parent().append('<div>Sibling</div>');
  });
});
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers