0

I have made an ajax call that returns a string of html. I want to add a class to an element inside that string of html. Then I want to take this newly modified html string and reassign it to the same variable as before. I'm noticing that, if I have this html string that looks like:

section
  div
  /div
section

and if I print it out, I see the section with a div inside. But if i do $(html_data).html() then it only shows the div as the root element. If I console.log($(html_data)) I can see the section. But again, console.log($(html_data).html()) shows the top element as being the div. It's as if wrapping the string inside $() removes the top element.

I cannot use $(html_data).outerHTML(). I get an error that says it's not a function.

How can I accomplish my goal?

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Captainlonate
  • 4,878
  • 4
  • 25
  • 35

0 Answers0