an applicationGets and sets the textual content and HTML content of an element
Two code
<script language= "javascript" src= "Js/jquery-3.1.1.min.js" ></script>
Applying the text () method to set the content
<div Id= "Div1" >
<span id= "Clock" > Current time: 2011-07-06 Wednesday 13:20:10</span>
</div>
<br/ > Apply HTML () method set content
<div id= "Div2" >
<span id= "Clock" > Current time: 2011-07-06 Wednesday 13:20:10</span>
</div>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#div1") . Text ("<span style= ' color: #FF0000 ' > I am the HTML content set through the text () method </span>");
$ ("#div2"). HTML ("<span style= ' color: #FF0000 ' > I am the HTML content set through the HTML () method </span>");
Alert ("Get through the Text () method: \ r \ n" +$ ("div"). Text () + "\ r \ n through the HTML () method to get: \ r \ n" +$ ("div"). html ());
</script>
three running effect
Four run analysis 1, when the text () is applied to set the textual content, even if the content contains HTML code, it will be considered as normal text, and can not be interpreted as HTML code browser, and the application of HTML () set HTML content included in the HTML code can be browsed The resolution of the device. 2. When the text () method is used to get the textual content, the text content contained in all matching elements is obtained, and when the HTML () method is used to get the HTML content, only the HTML content contained in the first matching element is obtained. Size: KB View picture Attachments