JQuery contents()
The contents() method is a jQuery method that returns all the child nodes of the selected HTML element, including both text and HTML elements.
Syntax
The content() method has the following syntax:
$(selector).contents()
Use
The contents() method is useful when you want to retrieve all the child nodes of an HTML element, including text nodes and HTML element nodes, and perform some manipulation on them.
Unlike the children() method, the contents() method returns not only the direct children of the selected element, but all the descendants of the element, including nested HTML elements.
Example
Here is an example of using the contents() method to retrieve all the child nodes of a selected element: