.contents() in jQuery

It helps to get the children of each element in the set of matched elements, including text and comment nodes.

.contents()

// HTML Content
<div>Data01</div>
<div><i>Data02</i></div>
<div>Data03</div>
<div>Data04</div>

// To search for all the text nodes inside the div element(Italic) and wrap them with a b(bold) element.

$(“div”).contents().filter(“i”).wrap(“<b/>”);

// OUTPUT
Data01
Data02
Data03
Data04