tags:

views:

44

answers:

2

Hey,

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!

+3  A: 

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
A: 

Take a look at the accepted answer in this post.

elusive