jQueryのcontentsメソッドの適用
テキストを含む全ての子孫要素を返すには、
contentsメソッドを
適用する必要があります。
以下はHTMLコードです:
<p id="test">text1 <b>bold</b> text2</p>
次に、contentsメソッドを利用しましょう:
$('#test').contents().each(
function() {
console.log($(this).text()); // 'text1', 'bold', 'text2' と出力されます
}
);
前の課題の解答コードを修正し、
contentsメソッドを使用して、
テキストを含むdivのすべての子孫要素を出力してください。