Skip to the content.

$.fn.html([content])

Get or set the inner HTML of every element in the collection.

When called with no arguments, returns the innerHTML of the first element. When called with a string, TrustedHTML value, or callback, replaces the HTML of every element.

Signatures

html(): string | undefined;
html(content: string | TrustedHTML | ((this: Element, index: number, currentHTML: string) => string)): this;

Parameters

Returns

When getting, the innerHTML of the first element, or undefined if the collection is empty. When setting, the original Dabby collection for chaining.

Examples

import $ from "dabbyjs";
import "dabbyjs/manipulation/html/html";

// Read the current contents
const current = $("#summary").html();
import $ from "dabbyjs";
import "dabbyjs/manipulation/html/html";

// Replace HTML directly
$("#summary").html("<p>Loading…</p>");
import $ from "dabbyjs";
import "dabbyjs/manipulation/html/html";

// Compute a new value from the current HTML
$(".article").html(function (index, current) {
    return current + "<p class='read-more'>Read more →</p>";
});

Trusted Types

Pass a TrustedHTML value to satisfy require-trusted-types-for 'script'. Strings continue to work; Dabby wraps them through its own dabby policy when one is available.

See also