← Back to Index

.append()

Inserts content to the end of each element in the set of matched elements.

Examples

1. Append HTML string

$('ul').append('<li>New Item</li>');

Result

<ul>
     <li>Existing Item</li>
     <li>New Item</li>
</ul>

2. Append existing element (Move)

// Moves #footer to inside .container
$('.container').append($('#footer'));

Result

<div class="container">
     <!-- other content -->
     <div id="footer">...</div>
</div>

3. Append SR Object

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

Result

<div>
     <!-- other content -->
     <span class="highlight">...</span>
</div>

Parameters

Parameter Type Description
content string | element | SR HTML string, DOM element, or SR object to insert at the end of each matched element.

Returns: The original SR object for chaining.