Skip to content

Instantly share code, notes, and snippets.

@sebm
Created May 23, 2012 08:28
Show Gist options
  • Save sebm/2773901 to your computer and use it in GitHub Desktop.
Save sebm/2773901 to your computer and use it in GitHub Desktop.
JS snippets for my blog post
var wrapper = document.createElement('div');
var outer = document.getElementById('whatever')
var nodes = outer.childNodes;
var elementsWidth = 0;
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].nodeType === Node.ELEMENT_NODE
&& nodes[i].tagName === 'IMG'
) {
elementsWidth += nodes[i].width;
wrapper.appendChild(nodes[i]);
}
}
outer.appendChild(wrapper);
outer.find('img').wrapAll('<div />')
container.append('<button>text</button>')
var button = document.createElement('button');
button.innerHTML = 'text';
container.appendChild(button);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment