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
For more information, refer to: http://www.softwhy.com/jquery/
What is the difference between the two jquery methods of HTML () and text ()?