Home>Article>Web Front-end> How to use the html() method in jquery
In JavaScript, the usage of the "html()" method is "element.html (new content of the selected element)". The html method sets or returns the content of the selected element. When this method is used to return content, the content of the first matching element is returned; when this method is used to set content, the content of all matching elements is rewritten.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
HTML content means that the content can contain HTML tags and can be rendered by the browser.
The text content is to first convert the HTML predefined characters in the content into html character entities, so that the HTML tags will not be rendered.
Syntax structure one:
$(selector).html()
At this time, when the method does not take parameters, it obtains the html content of the first matching element.
This method is similar to the text() method without parameters, but there are still big differences:
1.html() method obtains the content of the first matching element, while text() The method is to obtain the content contained in all matching elements.
2. The html() method obtains the content html content, while the text() method obtains the text content.
Example code:
- 欢迎您
The above code will return the content in the div element.
Grammar structure 2:
$(selector).html(content)
With parameters, it sets the html content of all matching elements.
This method is similar to the text() method with parameters, but there is still a big difference:
The html() method sets the html content, while the text() method sets the text content.
Example code:
The following code sets the html content in the div to "a4b561c25d9afb9ac8dc4d70affff419I am the content after reset0d36329ec37a2cc24d42c7229b69747a".
脚本之家 原来内容
[Recommended learning:javascript advanced tutorial]
The above is the detailed content of How to use the html() method in jquery. For more information, please follow other related articles on the PHP Chinese website!