0

I'm trying to modify HTML string by converting it to jQuery object, and then back to a string, but I'm losing somehow the parent element:

var code = '<div><img src="" /></div>';
var html = $(code);
console.log(html.html());

Output:

<img src="">

Instead of expected:

<div><img src=""></div>

How to get all elements back?

Eugene
  • 578
  • 6
  • 20
  • The issue is because you're getting the `html()` from the parent `div`, so it's own HTML is not included. There are lots of methods to get the outerHTML using jQuery - see the duplicate for more information – Rory McCrossan Oct 26 '21 at 19:51

0 Answers0