0

Does anybody know, if i have an object like $('#input') how can I get the html that would make it up, like <input id="input" /> as a text string?

Thanks!

JasCav
  • 34,458
  • 20
  • 113
  • 170
tarnfeld
  • 25,992
  • 41
  • 111
  • 146

1 Answers1

3

Any of the outerHTML plugins, like this will work:

jQuery.fn.outerHTML = function() {
  return jQuery('<div />').append(this.clone()).html();
}

Then just call it, e.g.:

var html = $("#input").outerHTML();

You can give it a try here, all of those plugins use basically the same concept, clone it, stick it in a container, get the innerHTML of that container.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155