The difference between the textual content of jquery elements and HTML content operations __html

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.