JQuery : get selected element outerHTML

AcceuilCategory: JQueryJQuery : get selected element outerHTML
Kanzari Haithem Staff asked 1 month ago

To get the current selected element outerHTML, we can use the JQuery Clone function and wrap it in a div then get the last created div html, the code looks like following :


var $clone = $(this).clone();
$clone.wrap('<div>');
var htmlString = $clone.parent().html();
console.log(htmlString);