0

I'm using jquery to parse some HTML, something like:

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

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

But at one point a need the whole HTML of the current element (not what innerHTML or .html() return) and I can't figure out a one liner to get it (I always could attach the tag and the attributes manually to the innerHTML).

For example:

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

The innerHTML is Link but I'm looking for the whole <a href="link">Link</a>

does that oneliner exists?

Cœur
  • 34,719
  • 24
  • 185
  • 251
MarcosPri
  • 167
  • 1
  • 9

2 Answers2

1

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

Justin Swartsel
  • 3,421
  • 1
  • 19
  • 24
0

just saw the anwser for this on the other thread :D

outerHTML

outerHTML 2

antpaw
  • 14,544
  • 11
  • 55
  • 86