.html()Returns: String
Description: Get the HTML contents of the first element in the set of matched elements.
version added: 1.0.html()
- This method does not accept any arguments.
This method is not available on XML documents.
In an HTML document, .html()
can be used to get the contents of any element. If the selector expression matches more than one element, only the first match will have its HTML content returned. Consider this code:
1 |
|
In order for the following <div>
's content to be retrieved, it would have to be the first one with class="demo-container"
in the document:
1 2 3 |
|
The result would look like this:
1 |
|
This method uses the browser's innerHTML
property. Some browsers may not return HTML that exactly replicates the HTML source in an original document. For example, Internet Explorer sometimes leaves off the quotes around attribute values if they contain only alphanumeric characters.
Example:
Click a paragraph to convert it from html to text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|