← Back to Index

.add()

Adds elements to the current set of matched elements.

Examples

1. Add by selector string

const $set = $('div').add('p');
$set.css('border', '1px solid red');

Result

<!-- matched elements -->
<div style="border: 1px solid red;">...</div>
<p style="border: 1px solid red;">...</p>

2. Add elements from another SR object

const $spans = $('span');
$('div').add($spans).addClass('highlight');

Result

<div class="highlight"></div>
<span class="highlight"></span>

3. Add a single element via an SR object

const $btn = $('#myBtn');
$('div').add($btn).hide();

Result

<div style="display: none;"></div>
<button id="myBtn" style="display: none;">Click</button>

Parameters

Parameter Type Description
selector string | element | SR A string selector, a DOM element, or an SR object to add to the set.

Returns: A new SR object containing the combined set.