jQuery HTML Manipulation

  • Previous Page
  • Next Page

jQuery includes many powerful functions for changing and manipulating HTML.

Change HTML content

Syntax

$(selector).html(content)

The html() function changes the content (innerHTML) of the matched HTML elements.

Example

$("p").html("W3School");

Try It Yourself

Add HTML content

Syntax

$(selector).append(content)

The append() function appends content to the internal HTML of the matched HTML elements.

Syntax

$(selector).prepend(content)

The prepend() function prepends content to the internal HTML of the matched HTML elements.

Example

$("p").append(" CodeW3C.com");

Try It Yourself

Syntax

$(selector).after(content)

The after() function inserts HTML content after all matching elements.

Syntax

$(selector).before(content)

The before() function inserts HTML content before all matching elements.

Example

$("p").after(" CodeW3C.com.");

Try It Yourself

jQuery HTML Manipulation - From This Page

Function Description
$(selector).html(content) Change the (internal) HTML of the selected element
$(selector).append(content) Append content to the (internal) HTML of the selected element
$(selector).prepend(content) Prepend content to the (internal) HTML of the selected element
$(selector).after(content) Add HTML after the selected element
$(selector).before(content) Add HTML before the selected element

For the complete reference manual, please visit our jQuery HTML Manipulation Reference Manual.

  • Previous Page
  • Next Page