jquery learning------HTML () and text ()
The similarities and differences between HTML and. Text:
- The. Html method operation is the same as the. text, except that it is specific to the processing object
- . HTML handles the content of elements,. Text handles textual content
- . HTML can only be used in HTML documents, and. Text can be used in both XML and HTML documents
- If the object you are working with has only one child text node, the result of HTML processing is the same as text.
- Firefox does not support the InnerText property, using a similar textcontent property, the. Text () method combines support for 2 properties, so it can be compatible with all browsers
Example:
<div class= "Soulsjie" >
</div>
<p></p>
<p></p>
<script type= "Text/javascript" >
Show what the HTML method gets
. HTML () is the entire HTML document structure
$ (' P:first '). Text ($ (". Soulsjie"). HTML ())
Shows what the text method gets
. Text () is a collection of textual content
$ (' p:last '). Text ($ (". Soulsjie"). Text ())
</script>
Output Result:
Simply speaking, use. html () to get tags and content to HTML, and use. Text () to get only the contents of the label
Get the original content, modify it, and re-assign it through the callback of the. Text ()
<script type= "Text/javascript" >
$ (". Left A:first"). Text (function (idnex,text) {
Index is the meaning of the indexed value, the index is $ ('. Left A:first '), and the other argument text is an existing text content in $ ('. Left A:first ')
Return ' Add new text content ' + text
})
</script>
jquery learning------HTML () and text ()