How To: jQuery - Get an Element's Outer HTML

A jQuery selector returns a new jQuery object that contains an array of DOM elements that match the CSS selector. To access an underlying DOM element within a jQuery object use the get method or square brackets. With the DOM element, the innerHTML attribute can be used to get the element's outer HTML.

Example

// Using the jQuery get method
var outerHtml = $("div").get(0).outerHTML;
 
// Using square brackets
var outerHtml = $("div")[0].outerHTML;
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License