Skip to content

Instantly share code, notes, and snippets.

@lirongfei123
Created September 20, 2016 06:50
Show Gist options
  • Save lirongfei123/1784a18153908e5410581cf351771773 to your computer and use it in GitHub Desktop.
Save lirongfei123/1784a18153908e5410581cf351771773 to your computer and use it in GitHub Desktop.
function cloneImg (elem) {
var imgNode = document.createElement("div");
var attributes = elem.attributes;
for (var i in attributes) {
if(!attributes.hasOwnProperty(i)) {
continue;
}
var attr = attributes[i];
if(attr.name == 'class') {
imgNode.className = attr.value;
continue;
}
imgNode.setAttribute(attr.name, attr.value);
}
return imgNode;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment