[ACCEPTED]-jQuery: Get HTML including the selector?-jquery-selectors

Accepted answer
Score: 55

In this specific case:

var outerHTML = $("<div />").append($('#example').clone()).html();

See this page for more details.

And 3 the discussion here: http://api.jquery.com/html/ (this explains that 2 this isn't in jQuery core and why some logical 1 solutions won't work)

Score: 6

You could try this:

var html = $('<div>').append($('#example').clone()).html();


Score: 2

For browsers that support it, outerHTML 3 can do that. There are jQuery plugins like 2 this and this that enable support via some clever 1 jQuery.

More Related questions