Home >Web Front-end >JS Tutorial >Usage examples of html() method in jQuery_jquery
The example in this article describes the usage of the html() method in jQuery. Share it with everyone for your reference. The specific analysis is as follows:
This method can set and get the HTML content of the matching element, and the original content will be replaced by the newly set content.
Special instructions:
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.
Grammar structure 1:
At this time, when the method takes no 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. The html() method obtains the content of the first matching element, while the text() method obtains the content contained in all matching elements.
2. The html() method obtains the 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:
With parameters, it sets the html content of all matching elements.
This method is similar to the text() method with parameters, but there are still big differences:
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 "I am the reset content".
实例二:
通过此实例大家可以观察一下html内容和文本内容的区别。
希望本文所述对大家的jQuery程序设计有所帮助。