jQuery HTML Manipulation
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");
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");
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.");
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.