I would like to get a specific tag element with its attributes from the DOM. For example, from
<a href="#" class="class"> link text </a>
I want to get <a href="#" class="class"> , optionally with closing </a> , either as a string, or some other object. In my opinion, this would be like extracting .outerHTML without .innerHTML .
Finally, I need this to wrap some other elements through jQuery. I tried
var elem = $('#some-element').get(0); $('#some-other-element').wrap(elem);
but .get() returns a DOM element, including its contents. Also
var elem = $('#some-element').get(0); $('#some-other-element').wrap(elem.tagName).parent().attr(elem.attributes);
does not work, because elem.attributes returns a NamedNodeMap that does not work with jQuery attr() , and I could not convert it. It was accepted that the above examples are not very clear, since they also copy the no-long-unique ID element. But is there an easy way? Many thanks.
javascript jquery dom innerhtml
Richard Kiefer
source share