html() in jQuery
Using this method it can get the HTML contents of the first element in the set of every matched element.
Browser's innerHTML property is used by this method.
Syntax 1 - Get the HTML contents of the first element in the set of matched elements.
Syntax 2 - Set the HTML contents of each element in the set of matched elements.
- htmlString - A string of HTML to set as the content of each matched element.
Syntax 3 - A function returning the value to set
- index - Index position of the element in the set.
- currentHtmlString - The old HTML value.
Example 1 - get html string
Example 2 - set html string
Example 3 - get old html string and set new html string
Example 4 - Execution steps
Difference between html() and text()
Using text() method it retrieves only the text from an element, but using html() method both the text as well as the HTML markup can be retrieved from the element.