Can I get a complete HTML representation of an HTMLElement DOM object?

I am using jquery to parse some HTML, something like:

$(html).contents().each(function(){
  var element = this.tagName;
  ...

I can access tagName, children, parent ... using the DOM or more friendly jQuery functions.

But at some point all the HTML of the current element is needed (not something that is returned innerHTMLeither .html()), and I cannot find one liner to get it (I could always attach the tag and attributes manually for innerHTML).

For instance:

<a href="link">Link</a>

innerHTML- Linkbut I'm looking for everything<a href="link">Link</a>

Does this oneliner exist?

0
source share
2 answers

Looks like this guy has a pretty great solution using jQuery: outerHTML

+1
0

Source: https://habr.com/ru/post/1725883/


All Articles