Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Last active October 13, 2015 08:24
Show Gist options
  • Select an option

  • Save swapnilshrikhande/9b04ae1935a17575e4aa to your computer and use it in GitHub Desktop.

Select an option

Save swapnilshrikhande/9b04ae1935a17575e4aa to your computer and use it in GitHub Desktop.
Find all attributes of an dom element and cloning it
//finding all attributes of an element.
$(this).each(function() {
$.each(this.attributes, function() {
// this.attributes is not a plain object, but an array
// of attribute nodes, which contain both the name and value
if(this.specified) {
console.log(this.name, this.value);
}
});
});
//new element / target element
var textAreaElem = $("<textarea />");
//source element
$("#input").each(function() {
$.each(this.attributes, function() {
// this.attributes is not a plain object, but an array
// of attribute nodes, which contain both the name and value
if(this.specified) {
textAreaElem.attr(this.name, this.value);
}
});
});
$("#input").replaceWith(textAreaElem);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment