Traversing
parent()
Get the parent of each element in the current set of matched elements.
Example
$(‘button’).on(‘click’, (e) => {
$(e.target).parent().toggleClass(‘my-class’);
});
next()
Get the immediately following sibling of each element in the set of matched elements.
Example
$(‘button’).on(‘click’, (e) => {
$(e.target).next().toggleClass(‘my-class’);
});
first()
Reduce the set of matched elements to the first in the set.
Example
$(‘button’).on(‘click’, (e) => {
$(e.target).first().toggleClass(‘my-class’);
});