Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <ul id="ul">
    <li>Firefox</li>
    <li>Chrome</li>
    <li>Opera</li>
    <li>Safari</li>
    <li>Internet Explorer</li>
    <li id="test">test</li>
  </ul>
</body>
</html>
 
var test  = document.getElementById('test');
var fragment = document.createDocumentFragment();
function wilEach(els, cb) {
    for(var i = 0, len = els.length; i < len; i++) {
        if (i === len) break;
        cb(els[i], i);
    }
}
// var child = [].slice.call(element.children);
// // for(var i = 0; i < child.length; i++) {
// //   if (i === child.length) break;
// //   console.log(child[i])
// //   fragment.appendChild(child[i]);
// // }
// wilEach(child, function(item) {
//   fragment.appendChild(item);
// });
function wilWrapInner(el, wrapInner) {
  var _el = [].slice.call(el.children);
  var fragment = document.createDocumentFragment();
  el.insertAdjacentHTML('afterbegin', wrapInner);
  var _wrap = el.children[0];
  for (var i = 0, len = _el.length; i < len; i++) {
    fragment.appendChild(_el[i]);
  }
  _wrap.appendChild(fragment);
}
wilWrapInner(test, '<div class="wrapinner"></div>');
// document.getElementById('test').appendChild(fragment);
Output 300px

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

Dismiss x
public
Bin info
anonymouspro
0viewers