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