The children method for working with descendants in jQuery
To work with the descendants of an element, we will first look at the children method, which allows you to get only the immediate descendants of an element.
Consider the following HTML code:
<p id="test">text1 <b>bold</b> text2</p>
To obtain descendants, we write the following function in the method:
$('#test').children().each(
function() {
console.log($(this).text()); // will bring out 'bold'
}
);
We have a div with tags:
<div id="text"><i>text1</i> <b>text2</b> text3 text4</div>
Print all immediate children of this div to the console using the children method.