Get the HTML contents of the first element in the set of matched elements or set the contents of every matched element.
// <div class="content"><span>Hi</span></div>
const content = $('.content').html();
"<span>Hi</span>"
$('.content').html('<strong>New Content</strong>');
<div class="content">
<strong>New Content</strong>
</div>
You can pass a DOM element or SR object. The container will be emptied, and the element will be appended.
const $iframe = $.t('<iframe>', { src: '/page' });
$('.frame-container').html($iframe);
<div class="frame-container">
<iframe src="/page"></iframe>
</div>
$('div').html((index) => `<span>Item ${index}</span>`);
<div><span>Item 0</span></div>
<div><span>Item 1</span></div>
| Parameter | Type | Description |
|---|---|---|
| content | string | element | SR | function | The content to set. Can be an HTML string, a DOM element, an SR object, or a function returning any of these. Function receives (index, currentHtml). |
Returns: The innerHTML string for getter, or the original SR object for setter.