jQuery HTML Method
jQuery provide 3 methods to set or Get the content from a DOM element i.e. text() , html() and val() . jQuery html() method get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element. Also, by using HTML() with a jQuery object you can replace the contents of any container element like the < div > or < p >, < span > and others. When this method is used to set content, it overwrites the content of ALL matched elements. It is important to note that This method uses the browser's innerHTML property . Some browsers may not return HTML that exactly replicates the HTML source in an original document.
Get HTML Contents with html() Method
Set HTML Contents with html() Method
Difference between jQuery: text() and html() ?
- .text() can be used in both XML and HTML documents.
- .html() is only for html documents.