Last active
October 13, 2015 08:24
-
-
Save swapnilshrikhande/9b04ae1935a17575e4aa to your computer and use it in GitHub Desktop.
Find all attributes of an dom element and cloning it
This file contains hidden or 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
| //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