Using the contents method in jQuery
To return all descendants, including text, use the contents method.
Below is the HTML code:
<p id="test">text1 <b>bold</b> text2</p>
Now let's use the method contents:
$('#test').contents().each(
function() {
console.log($(this).text()); // will bring out 'text1', 'bold', 'text2'
}
);
Correct the code for solving the previous problem, output all the children of the div, including the text, using the contents method.