← Back to Index

.prepend()

Insert content to the beginning of each element in the set of matched elements.

Examples

1. Prepend HTML

// <ul><li>B</li></ul>
$('ul').prepend('<li>A</li>');

Result

<ul>
     <li>A</li>
     <li>B</li>
</ul>

2. Prepend Element

const $icon = $.t('<i>');
$('button').prepend($icon);

Result

<button>
     <i></i>
     Click Text
</button>

Parameters

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

Returns: The original SR object for chaining.