Change HTML content syntax
$(selector).html(content)
The HTML () function changes the content of the matched HTML element (innerhtml ).
Instance
$("p").html("W3School");
Add HTML content syntax
$(selector).append(content)
The append () function appends content to the matched HTML element.
Syntax
$(selector).prepend(content)
The prepend () function provides the prepend content to the matched HTML element.
Instance
$("p").append(" W3School");
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.
Instance
$("p").after(" W3School.");
Jquery document Operation MethodThese methods are applicable to both XML and HTML documents except HTML ().
Method |
Description |
Addclass () |
Add the specified class name to the matched element. |
After () |
Insert content after matching elements. |
Append () |
Append content to the matching element. |
Appendto () |
Append content to the matching element. |
ATTR () |
Sets or returns the attributes and values of matching elements. |
Before () |
Insert content before each matching element. |
Clone () |
Create a copy of the Matching Element Set. |
Detach () |
Removes a set of matching elements from the Dom. |
Empty () |
Delete all child nodes in the matched element set. |
Hasclass () |
Check whether the matched element has the specified class. |
HTML () |
Sets or returns the HTML content of the matched element set. |
Insertafter () |
Insert matched elements to the end of another specified Element Set. |
Insertbefore () |
Insert the matched element to the front of another specified Element Set. |
Prepend () |
Forward content to each matching element. |
Prependto () |
Forward content to each matching element. |
Remove () |
Remove all matched elements. |
Removeattr () |
Removes the specified attribute from all matched elements. |
Removeclass () |
Deletes all or specified classes from all matching elements. |
Replaceall () |
Replace all matched elements with matched elements. |
Replacewith () |
Replace the matched element with the new content. |
Text () |
Sets or returns the content of the matching element. |
Toggleclass () |
Adds or deletes a class from a matched element. |
Unwrap () |
Removes and replaces the parent element of the specified element. |
Val () |
Sets or returns the value of the matching element. |
Wrap () |
Enclose matched elements with specified content or elements. |
Wrapall () |
Enclose all matching elements with specified content or elements. |
Wrapinner () |
Enclose the child content of each matching element with the specified content or element. |