next()
method?Thenext()
jQuery method is a traversing method used to locate the next element of the selected group. If we have <div>
before an <ul>
element, the next()
method will help us locate the <ul>
. Moreover, we don't need to know the next element.
$(selector).next(filter)
children()
method?The children()
method is a jQuery traversing method that returns the direct children of a selected HTML element. This means that we don't need to know the children of the selected element with this method. We can select the children and, if we like, change the styling, as we see in the example below:
$(selectorfilter).children()
In lines 10 and 11, we select an element with the same class. However, in line 10, we add a red border styling to the next element and a purple border styling to the children elements in line 11. Thus, we notice in the output that the elements enclosed inside the <div>
with class start
are styled with the purple border, while the <p>
element is styled with the red border.
RELATED TAGS
CONTRIBUTOR
View all Courses