-
-
Save sebm/2773901 to your computer and use it in GitHub Desktop.
JS snippets for my blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outer.find('img').wrapAll('<div />') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
container.append('<button>text</button>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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