如何从JavaScript中的HTML字符串中提取div内的所有内容

问题描述:

我有这样的HTML字符串:-

I have a HTML string like this :-

var html = '<div id="parent_div">
            <div id="child_div">
            <ul>
             <li><img src="wow/img1.jpg" /><a href="http://wow.com">wow link</a></li>
             <li><img src="wow/img2.jpg" /><a href="http://wow.com">wow link</a></li>
            </ul>
            </div>
            </div>';

如何提取<div id="parent_div">内部的所有内容?

How to extract all the contents inside the <div id="parent_div"> ?

在jQuery中,您可以执行$($html).html();

In jQuery you could just do $($html).html();

在php中,您可以使用简单的HTML DOM

In php you could use something like Simple HTML DOM