How to extract all contents inside a div from HTML string in JavaScript
问题 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>'; How to extract all the contents inside the <div id="parent_div"> ? 回答1: In jQuery you could just do $($html).html(); In php you could use something like Simple HTML DOM 回答2: Take a look at DOM or the other PHP XML libs. http://se.php