What is the difference between the two jquery methods of HTML () and text ()?

Source: Internet
Author: User

What is the difference between the two jquery methods of HTML () and text ():
The two methods in the title are the two common methods of jquery, and sometimes the function seems to be exactly the same, in fact, this is just an illusion, the following examples to introduce their differences, first look at a code example:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title> <styletype= "Text/css">Div{width:150px;Height:30px;Line-height:30px; } </style> <Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script> <Scripttype= "Text/javascript">$ (document). Ready (function(){   $(". html"). HTML ("Ant Tribe"); $(". Text"). Text ("Ant Tribe"); }) </Script> </Head> <Body> <Divclass= "html"></Div> <Divclass= "text"></Div> </Body> </HTML>

In the above code, two methods can be set to the content of the div in the "Ant tribe", as if the function is identical.
Take another look at the example code:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Ant Tribe</title> <styletype= "Text/css">Div{width:150px;Height:30px;Line-height:30px; } </style> <Scripttype= "Text/javascript"src= "Mytest/jquery/jquery-1.8.3.js"></Script> <Scripttype= "Text/javascript">$ (document). Ready (function(){   $(". html"). HTML ("<b> Ant Tribe </b>"); $(". Text"). Text ("<b> Ant Tribe </b>"); }) </Script> </Head> <Body> <Divclass= "html"></Div> <Divclass= "text"></Div> </Body> </HTML>

In the above code it is obvious that the two different points of the method, the HTML () method can be like a browser to parse the HTML code, and the text () method is just the HTML code as normal text, so the difference between them is obvious.

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=5794

More information: http://www.softwhy.com/jquery/

What is the difference between the two jquery methods of HTML () and text ()?

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.