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,060
  • 20
  • 106
  • 167
tarnfeld
  • 24,994
  • 39
  • 109
  • 145

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
  • 610,884
  • 134
  • 1,288
  • 1,151