jQuery | children() with Examples
children() is an inbuilt method in jQuery which is used to find all the children element related to that selected element. This children() method in jQuery traverse down to a single level of the selected element and return all elements.
Here selector is the selected element whose children are going to be found.
Parameter: It does not accept any parameters.
Return values: It returns all the children of the selected element.
Code #1: In the below code, all the elements directly connected to the “div” element get highlighted with the green color.
An optional parameter can also be used to the children() method to filter the search for children elements.
Here selector1 is the selected element whose children are going to be found.
Parameters: It accepts a parameter which is specified below-
Return value: It returns the prior children of the selected element.
Code #2: In the below code, among all the paragraph element, elements of first paragraph gets selected and highlighted with thegreen color.
You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.