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
  • 37,241
  • 25
  • 195
  • 267
MarcosPri
  • 177
  • 1
  • 10

2 Answers2

1

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

Justin Swartsel
  • 3,451
  • 1
  • 20
  • 24
0

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

outerHTML

outerHTML 2

antpaw
  • 15,444
  • 11
  • 59
  • 88