← Back to Index

.parent()

Get the parent of each element in the current set of matched elements.

Examples

1. Get parent

// <div class="wrap"><button>Hi</button></div>
$('button').parent().addClass('found');

Result

<div class="wrap found">...</div>

2. Filter parent

// <div class="active"><span>A</span></div>
// <div><span>B</span></div>
$('span').parent('.active');

Result

// Only returns the parent of A
[ <div class="active">...</div> ]

Parameters

Parameter Type Description
selector string Optional. A string containing a selector expression to match the parent against.

Returns: A new SR object.