world!"); }); ``` --- ##"> world!"); }); ``` --- ##" />
Easy Tutorial
❮ Html Insertafter Misc Deferred Notifywith ❯

jQuery html() Method

jQuery HTML/CSS Methods

Example

Change the content of all <p> elements:

$("button").click(function(){
    $("p").html("Hello <b>world</b>!");
});

Definition and Usage

The html() method sets or returns the content of the selected elements (innerHTML).

When used to return content, it returns the content of the first matched element.

When used to set content, it overwrites the content of all matched elements.

Tip: To set or return only the text content of the selected elements, use the text() method.


Syntax

Return content:

Set content:

Set content using a function:

Parameter Description
content Required. Specifies the new content for the selected elements (can include HTML tags).
function(index, currentcontent) Optional. A function that returns the new content for the selected elements. index - Returns the index position of the element in the set.<br><br>currentcontent - Returns the current HTML content of the selected element.

More Examples

Return Element Content

Set Element Content Using a Function


jQuery HTML/CSS Methods

❮ Html Insertafter Misc Deferred Notifywith ❯