The children()
method is a jQuery traversing method that returns the direct children of a selected HTML element. It means we don't need to know the children of the selected element with this method. We can select the children and change the styling, as we see in the example below.
$(selectorfilter).children()
jQuery traversing helps to drill down or locate (or find) HTML elements relative to other elements. Selects an element first and goes through that selection until the desired element is reached. Let's see an example.
Let's look at the example below:
We select a parent element ul
and use the children()
method to access the children element and add some styling, as we see in the output.
Now try to change the li
element to a div
and the styling will remain in the result. This means that the styling remains as long as the element is a child of the ul
element.