简体   繁体   中英

How to get html inside a parent element from data_response?

I'm doing an ajax call, the data_response has a single HTML element with a lot of markup inside:

<div>**code I want to retrieve**</div>

I want to get the innerHtml without the parent element, so that I put it inside another element.

Basically:

$('selector').html(**code I want to retrieve**);

How can this be done?

If the response really just contains HTML, then you can parse it easily using JQuery:

var html = $(data_response).html();
$('selector').html(html);

Edit

It's the same principle as this:

var newElement = $("<div id='foo'>stuff</div>");
$("body").append(newElement);
var theElement = $("#foo");
console.log(theElement.html());

stuff

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM